1

Could you explane me what is wrong in this simple code?
It doesn't work with Gmail but yes with some other clients.

$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))

In Gmail I get something like this:

--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--
Nirav Madariya
  • 1,470
  • 2
  • 24
  • 37
Luca4k4
  • 89
  • 1
  • 10

0 Answers0