简体   繁体   中英

HTML e-mail in outlook using PHP mail() function

I am keep getting the source code in outlook 2013. I have read a lot of stackoverflow questions, tried all the recommended solutions, none of the helped tho.

here is my php

    $test1 = "test string";

// Retrieve the email template required
$message = file_get_contents('email-templates/template1.html');
// Replace the % with the actual information
$message = str_replace('%test1%', $test1, $message);

//echo $message;

$to = 'test@gmail.com';
$email_subject = "test";
$email_body = $message;

$headers = "From: $to\n";
$headers  .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";


mail($to,$email_subject,$email_body,$headers);

using only \\n instead of \\r\\n , and took care of the order (this one was presented), but still working on gmail, phone, bot does not in Outlook.

any more suggestions?

I suggest that rather trying to re-invent (or fix) the wheel that you use PHPMailer . I've been using it for years to send HTML emails that render properly in Outlook.

your code looks a lot like the example in the manpage http://php.net/manual/en/function.mail.php

try ending your lines with \\r\\n (CR-LF) not just newlines, who knows

You can back up a step, copy-and-paste the example from php.net and see whether the problem is really on the Outlook side. You can also pull up html emails from your inbox, and see what they're doing different (try to copy-and-paste send a copy of a good html email from within php)

As to reinventing the wheel, if mail() predates PHPMailer, arguably it's the latter that did the reinventing...

the solution was

$headers .= "MIME-Version: 1.0\n" ;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM