PHP - imap_mail_compose() 函式



PHP 的 IMAP 函式幫助您訪問電子郵件帳戶,IMAP 代表Internet Mail Access Protocol,使用這些函式您還可以使用 NNTP、POP3 協議和本地郵箱訪問方法。

imap_mail_compose() 函式接受包含標題欄位的兩個陣列和作為引數的訊息正文的索引陣列,並建立一個 MIME 訊息。

語法

imap_mail_compose($envelope, $body);

引數

序號 引數及描述
1

envelope (必填)

這是一個包含以下鍵的標題陣列:

remail、return_path、date、from、reply_to、in_reply_to、subject、to、cc、bcc、message_id 和 custom_headers。

2

body (必填)

這是一個表示訊息正文的陣列,包含以下鍵:

type、encoding、charset、type.parameters、subtype、id、description、disposition.type、disposition、contents.data、lines、bytes 和 md5。

返回值

此函式返回一個表示 MIME 訊息的字串值。

PHP 版本

此函式首次在 PHP 4 版本中引入,並在所有後續版本中均有效。

示例

以下示例演示了imap_mail_compose() 函式的使用:

<html>
   <body>
      <?php
         $envelope["from"]= "sender@test.com";
         $envelope["to"]  = "reciever1@test.com";
         $envelope["cc"]  = "reciever2@test.com";

         $mail_part1["type"] = TYPEMULTIPART;
         $mail_part1["subtype"] = "mixed";

         $mail_part2["type"] = TYPETEXT;
         $mail_part2["subtype"] = "plain";
         $mail_part2["description"] = "test_desc";
         $mail_part2["contents.data"] = "sample contents \n\n\n\t";

         $body[1] = $mail_part1;
         $body[2] = $mail_part2;

         print( imap_mail_compose($envelope, $body));
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

From: sender@test.com
To: reciever1@test.com
cc: reciever2@test.com
MIME-Version: 1.0
Content-Type: MULTIPART/mixed; BOUNDARY="15319133-10280-1603871611=:4416"

−−15319133-10280−1603871611=:4416
Content-Type: TEXT/plain; CHARSET=US-ASCII
Content−Description: test_desc

sample contents
−−15319133-10280-1603871611=:4416−−
php_function_reference.htm
廣告