My PHP mail()
always stops sending email when the From
header reaches a certain length. I’m using Cyrillic symbols in the From
header, so I have to encode it in windows-1251
(that’s the only encoding that seems to work in all HTML mail clients I need to support).
So, my code:
$to = 'myemail@test.com';
$subject = 'Cyrillic subject goes here';
$message = $letterbody; //letterbody gets form data and packs it into nice table
$headers = "MIME-Version: 1.0
";
$headers .= "Content-Transfer-Encoding: 8bit
";
//takes Lastname of the person registering, encodes it so all the clients can read, takes its email address
$headers .= "From: =?windows-1251?B?".base64_encode($lastname)."?= <$email>
";
$headers .= "Content-type: text/html; charset=\"windows-1251\"
";
mail($to,"=?windows-1251?B?".base64_encode($subject)."?=",$message,$headers);
So, for example, I set the $email
variable to test@test.com
and set $lastname
to "tttt". The email sends and $headers
looks like this (taken from a var_dump()
right before sending):
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
From: =?windows-1251?B?dHR0dHQ=?=
Content-type: text/html; charset="windows-1251"
If I add one more "t" with the same email address
$email = test@test.com;
$lastname = "tttttt"
the mail does not send and the $headers
look like this:
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
From: =?windows-1251?B?dHR0dHR0?=
Content-type: text/html; charset="windows-1251"
I have no idea what else I can do. With no encoding of the $lastname
it seems to be working fine, but then it’s unreadable on some email clients, such as Postfix on Ubuntu 13.
Maybe I need to set some $headers
limit in Postfix?