当标头达到一定长度时,我的 PHPmail()
总是停止发送电子邮件。From
我在From
标题中使用西里尔符号,所以我必须对其进行编码windows-1251
(这似乎是在我需要支持的所有 HTML 邮件客户端中工作的唯一编码)。
所以,我的代码:
$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\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
//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>\r\n";
$headers .= "Content-type: text/html; charset=\"windows-1251\"\r\n";
mail($to,"=?windows-1251?B?".base64_encode($subject)."?=",$message,$headers);
因此,例如,我将$email
变量设置为test@test.com
并设置 $lastname
为“tttt”。电子邮件发送并$headers
如下所示(取自var_dump()
发送前的右侧):
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
From: =?windows-1251?B?dHR0dHQ=?=
Content-type: text/html; 字符集="windows-1251"
如果我用相同的电子邮件地址再添加一个“t”
$email = test@test.com;
$lastname = "tttttt"
邮件不发送,$headers
看起来像这样:
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
From: =?windows-1251?B?dHR0dHR0?=
Content-type: text/html; 字符集="windows-1251"
我不知道我还能做什么。由于没有编码,$lastname
它似乎工作正常,但在某些电子邮件客户端上是不可读的,例如 Ubuntu 13 上的 Postfix。
也许我需要$headers
在 Postfix 中设置一些限制?