Отправка HTML и обычного текста в Gmail не работает

Не могли бы вы объяснить мне, что не так в этом простом коде?
Это не работает с Gmail, но да с некоторыми другими клиентами.

$boundary = md5( uniqid() . microtime() );
$to      =  $user;
$headers[] = 'From: my@email.com';
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-Type: multipart/alternative; boundary="'.$boundary.'"\r\n';
$subject = "The subject";
$message = "--" . $boundary . "\r\n";
$message .= "Content-type: text/plain; charset=utf-8\r\n";
$message .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$message .= 'Simple Text Message line 1\r\nline 2\r\nline 3';
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/html; charset=utf-8\r\n";
$message .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$message .= "<h1>html message!</h1>";
$message .= "\r\n\r\n--" . $boundary . "--";
mail($to, $subject, $message, implode("\r\n", $headers))

В Gmail я получаю что-то вроде этого:

--05fd97038918d12debb49153b3ad67a5
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Simple Text Message line 1\r\nline 2\r\nline 3

--05fd97038918d12debb49153b3ad67a5
Content-type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit

<h1>html message!</h1>

--05fd97038918d12debb49153b3ad67a5--

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …