Why is Outlook email changing my email into attachment with .dat extension?

Viewed 128

I'm sending a simple email using PHP mail() function in HTML content type. It works fine on every email, except Outlook, where whole content of my mail is transferred into an attachment with .dat extension. Why is it happening? Is there a way to fix it or to workaround?

I haven't found an explanation anywhere, why is it happening in so simple case. (Outlook settings are set to open emails as HTML and HTML emails sent from other websites looks fine too)

mail('myMail@gmail.com', "Testing", "First line<br>Second line <b>bolded text</b>", "From: myWebsite@mail.com\nContent-Type:".' text/html;charset="UTF-8"'."\nContent-Transfer-Encoding: 8bit");
1 Answers

Note that "extra headers should be separated with a CRLF (\r\n)" c.f. https://www.php.net/manual/en/function.mail.php

Try adding the MIME flag and see if it then works for you:

$headers = "From: myWebsite@mail.com \r\n".
           "Content-type: text/html; charset=UTF-8 \r\n".
           "Content-Transfer-Encoding: 8bit \r\n".
           "MIME-Version: 1.0";
    
mail('myMail@gmail.com', "Testing", "First line<br>Second line <b>bolded text</b>", $headers);
Related