PHP mail formatting issue - Why do CRLF header line endings break HTML email in Outlook?

前端 未结 4 1212
北海茫月
北海茫月 2020-12-18 13:49

I\'m using the PHP native mail() function to send HTML emails and have a formatting problem in the users most common email client - Outlook 2007

4条回答
  •  一向
    一向 (楼主)
    2020-12-18 14:07

    The email is been interpreted as text/plain instead of intended html. The reason for this is that text/html is a multipart subtype thus requiring boundary declarations.

    Your code is missing a the header boundary declaration:

    $message  = get_HTML_email_with_valid_formatting();
    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "--$boundary\r\n"."Content-Type: text/html; charset=ISO-8859-1\r\n";
    $headers .= "From: example.com \r\n";
    $headers .= "Reply-To: donotreply@example.com\r\n";
    mail('me@example.com', 'test', $message, $headers);
    

    Check this wiki about MIME & Multipart Messages: http://en.wikipedia.org/wiki/MIME#Multipart_messages

提交回复
热议问题