imap_mail_compose
(PHP 4, PHP 5, PHP 7, PHP 8)
imap_mail_compose — Create a MIME message based on given envelope and body sections
說明
$envelope, array $bodies): string|false
Create a MIME message based on the given envelope
and bodies sections.
參數
-
envelope -
An associative array of header fields. Valid keys are:
"remail","return_path","date","from","reply_to","in_reply_to","subject","to","cc","bcc"and"message_id", which set the respective message headers to the given string. To set additional headers, the key"custom_headers"is supported, which expects an array of those headers, e.g.["User-Agent: My Mail Client"]. -
bodies -
An indexed array of bodies. The first body is the main body of the message; only if it has a type of
TYPEMULTIPART, further bodies are processed; these bodies constitute the bodies of the parts.Body Array Structure Key Type Description typeint The MIME type. One of TYPETEXT(default),TYPEMULTIPART,TYPEMESSAGE,TYPEAPPLICATION,TYPEAUDIO,TYPEIMAGE,TYPEMODELorTYPEOTHER.encodingint The Content-Transfer-Encoding. One ofENC7BIT(default),ENC8BIT,ENCBINARY,ENCBASE64,ENCQUOTEDPRINTABLEorENCOTHER.charsetstring The charset parameter of the MIME type. type.parametersarray An associative array of Content-Typeparameter names and their values.subtypestring The MIME subtype, e.g. 'jpeg'forTYPEIMAGE.idstring The Content-ID.descriptionstring The Content-Description.disposition.typestring The Content-Disposition, e.g.'attachment'.dispositionarray An associative array of Content-Dispositionparameter names and values.contents.datastring The payload. linesint The size of the payload in lines. bytesint The size of the payload in bytes. md5string The MD5 checksum of the payload.
返回值
Returns the MIME message as string, 或者在失敗時返回 false.
範例
示例 #1 imap_mail_compose() example
<?php
$envelope["from"]= "[email protected]";
$envelope["to"] = "[email protected]";
$envelope["cc"] = "[email protected]";
$part1["type"] = TYPEMULTIPART;
$part1["subtype"] = "mixed";
$filename = "/tmp/imap.c.gz";
$fp = fopen($filename, "r");
$contents = fread($fp, filesize($filename));
fclose($fp);
$part2["type"] = TYPEAPPLICATION;
$part2["encoding"] = ENCBINARY;
$part2["subtype"] = "octet-stream";
$part2["description"] = basename($filename);
$part2["contents.data"] = $contents;
$part3["type"] = TYPETEXT;
$part3["subtype"] = "plain";
$part3["description"] = "description3";
$part3["contents.data"] = "contents.data3\n\n\n\t";
$body[1] = $part1;
$body[2] = $part2;
$body[3] = $part3;
echo nl2br(imap_mail_compose($envelope, $body));
?>