I am struggling with sending emails from PHP script. When the mail()
function is fired, AND the recipient has his mailbox hosted by a specific service (seznam.cz) AND the mail is downloaded into a mail client (Mozilla Thunderbird) AND ESET antivirus checks it, the message appears broken.
I think, that the problem is caused by antivirus inserting special header to the mail message and leaving empty line after that:
...
Subject: =?UTF-8?B?Tm92w70gxI1sZW4gd2VidSBBU1AgxIxSIQ==?=
X-EsetId: 37303A298C7FEE69657363
X-PHP-Originating-Script: 80:script.php
MIME-Version: 1.0
Content-type:text/html;charset=UTF-8
...
My email client thinks the message is plain text and begins with the line X-PHP-Originating-Script
. The rest of message includes all the HTML tags.
This is the script I used to send the email:
$subject = mb_encode_mimeheader('Subject text');
$emailBody = '<!DOCTYPE html>
<html lang="cs">
...
</html>';
$emailAltBody = "...";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <email.address@example.com>' . "\r\n";
$result = mail("email.address@example.com", $subject, $emailBody, $headers);
However, when using Laravel framework, the emails are sent and displayed correctly. I compared the differences and realized, that the X-PHP-Originating-Script
header is not sent by Laravel.
Could that be the reason? And how do I fix it?