Задача: отправить письмо в html и plain версиях.
Для этого взял класс SendMailSmtpClass и немного его модернизировал.
На gmail приходят нормальные html письма, а на mail.ru приходит такой текст:
--KJDFKLAJSDLFJADLKJ
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: binary
PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMDEgVHJhbnNpdGlvbmFs
Ly9FTiIgImh0dHA6Ly93d3cudzMub3JnL1RSL2h0bWw0L2xvb3NlLmR0ZCI+DQo8aHRtbD4NCjxo
ZWFkPg0KPG1ldGEgaHR0cC1lcXVpdj0iQ29udGVudC1UeXBlIiBjb250ZW50PSJ0ZXh0L2h0bWw7
IGNoYXJzZXQ9dXRmLTgiPg0KPC9oZWFkPg0KPGJvZHkgc3R5bGU9InBhZGRpbmc6MDsgbWFyZ2lu
OjA7IiBiZ2NvbG9yPSIjZjRmNGY0Ij4NCiAgICA8dGFibGUgd2lkdGg9IjEwMCUiIGJvcmRlcj0i
MCIgY2VsbHNwYWNpbmc9IjAiIGNlbGxwYWRkaW5nPSIwIiBiZ2NvbG9yPSIjZjRmNGY0IiBzdHls
ZT0ibWluLXdpZHRoOjY1MHB4IiBhbGlnbj0iY2VudGVyIj4NCiAgICAgICAgPHRyPg0KICAgICAg
ICAgICAgPHRkIHdpZHRoPSIyNSI+DQogICAgICAgICAgICAgICAgPCEtLSBwYWRkaW5nIC0tPjxk
aXYgc3R5bGU9ImhlaWdodDogNDBweDsgbGluZS1oZWlnaHQ6NDBweDsgZm9udC1zaXplOjQwcHg7
Ij4mbmJzcDs8L2Rpdj4NCiAgICAgICAgICAgIDwvdGQ+DQogICAgICAgICAgICA8dGQgd2lkdGg9
IjYwMCI+DQogICAgICAgICAgICAgICAgPCEtLVtpZiBndGUgbXNvIDEwXT4NCiAgICAgICAgICAg
ICAgICA8dGFibGUgd2lkdGg9IjYwMCIgYm9yZGVyPSIwIiBjZWxsc3BhY2luZz0iMCIgY2VsbHBh
ZGRpbmc9IjAiPg0KICAgICAgICAgICAgICAgICAgICAgIDx0cj48dGQ+PCFbZW5kaWZdLS0+DQog
ICAgICAgICAgICAgICAgICA8dGFibGUgY2xhc3M9Im1haW4iIHdpZHRoPSI2MDAiIGJvcmRlcj0i
MCIgY2VsbHNwYWNpbmc9IjAiIGNlbGxwYWRkaW5nPSIwIiBiZ2NvbG9yPSIjZjRmNGY0IiBzdHls
ZT0ibWluLXdpZHRoOjYwMHB4IiBhbGlnbj0iY2VudGVyIj4NCiAgICAgICAgICAgICAgICAgICAg
[много текста]
--KJDFKLAJSDLFJADLKJ--
Видимо я в заголовках накосячил, но не пойму где именно
function send($mailTo, $subject, $html, $plain = '', $headers = '') {
$contentMail = "Date: " . date("D, d M Y H:i:s") . " UT\r\n";
$contentMail .= 'Subject: =?' . $this->smtp_charset . '?B?' . base64_encode($subject) . "=?=\r\n";
$contentMail .= "MIME-Version: 1.0\r\n";
$contentMail .= "From: =?".$this->smtp_charset."?B?".base64_encode($this->smtp_from)."=?= <".$this->smtp_username.">\r\n"; // от кого письмо
if($plain == '') {
$contentMail .= "Content-type: text/html; charset=".$this->smtp_charset."\r\n"; // кодировка письма
$contentMail .= $headers . "\r\n";
$contentMail .= $html . "\r\n";
} else {
$contentMail .= "Content-type: multipart/alternative;";
$contentMail .= "boundary=\"KJDFKLAJSDLFJADLKJ\"\r\n";
$contentMail .= "--KJDFKLAJSDLFJADLKJ\r\n";
$contentMail .= "Content-Type: text/plain; charset=".$this->smtp_charset."\r\n";
$contentMail .= "Content-Transfer-Encoding: base64\r\n";
$contentMail .= chunk_split(base64_encode($plain));
$contentMail .= "\r\n";
$contentMail .= "--KJDFKLAJSDLFJADLKJ\r\n";
$contentMail .= "Content-Type: text/html; charset=".$this->smtp_charset."\r\n";
$contentMail .= "Content-Transfer-Encoding: base64\r\n";
$contentMail .= chunk_split(base64_encode($html));
$contentMail .= "\r\n";
$contentMail .= "--KJDFKLAJSDLFJADLKJ--\r\n";
}
....