For some email clients its necessary first to start with the body text and end with the attachment(s). Otherwise all the parts end up in attachments, also the body text (took a while to find this).
So example #1 (above) should be switched over, like:
$body[1] = $part1;
$body[2] = $part3;
$body[3] = $part2;imap_mail_compose
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
imap_mail_compose
Референца за `function.imap-mail-compose.php` со подобрена типографија и навигација.
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
= NULL
Креирај MIME порака врз основа на дадени делови за обвивка и тело envelope
and bodies sections.
Параметри
envelope-
Креирај MIME порака врз основа на даденото
"remail","return_path","date","from","reply_to","in_reply_to","subject","to","cc","bcc"and"message_id"Асоцијативен список на полиња за заглавие. Валидни клучеви се: string, кои ги поставуваат соодветните заглавија на пораката на даденото"custom_headers". За поставување дополнителни заглавија, клучот["User-Agent: My Mail Client"]. bodies-
се поддржува, кој очекува список на тие заглавија, на пр.
TYPEMULTIPARTИндексиран список на тела. Првото тело е главното тело на пораката; само ако има тип, се обработуваат понатамошни тела; овие тела ги сочинуваат телата на деловите. Можни индекси на низи за Тип = NULL typeint Структура на список на тело TYPETEXT(стандардно),TYPEMULTIPART,TYPEMESSAGE,TYPEAPPLICATION,TYPEAUDIO,TYPEIMAGE,TYPEMODELorTYPEOTHER.encodingint На Content-Transfer-EncodingMIME типот. Еден одENC7BIT(стандардно),ENC8BIT,ENCBINARY,ENCBASE64,ENCQUOTEDPRINTABLEorENCOTHER.charsetstring . Еден од type.parametersarray Асоцијативен array of Content-TypeПараметарот за карактер на MIME типот.subtypestring имиња на параметри и нивните вредности. 'jpeg'forTYPEIMAGE.idstring На Content-ID.descriptionstring На Content-Description.disposition.typestring На Content-Disposition, на пр.'attachment'.dispositionarray Асоцијативен array of Content-DispositionMIME подтипот, на пр.contents.datastring имиња и вредности на параметри. linesint Товарот. bytesint Големината на товарот во редови. md5string Големината на товарот во бајти.
Примери
Пример #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));
?>Белешки од корисници 5 белешки
The custom_headers envelope documentation is misleading. Its not actually an "associative array", its a regular array of headers.
This is wrong:
<?php
$envelope = [
//...
"custom_headers" => [
"X-SES-CONFIGURATION-SET" => "example",
"X-SES-MESSAGE-TAGS" => "emailType=example"
]
];
?>
This is right:
<?php
$envelope = [
//...
"custom_headers" => [
"X-SES-CONFIGURATION-SET: example",
"X-SES-MESSAGE-TAGS: emailType=example"
]
];
?>The documentation above does not mention that you can use the index ["charset"] to set the character set of the messsage part.
Example:
$part1["type"]= "TEXT";
$part1["subtype"]="PLAIN";
$part1["charset"] = "koi8-r";
to send a message in Russian-koi8.
Scott =)If you wish to send the output of this function, simply use it for the headers argument of imap_mail() or mail(). Keep in mind that those functions set the To: and Subject: headers, so including them in the envelope will create double entries.It is a good idea to set the date header:
$envelope['date']=date('r');