PHP邮件附件坏标头?

时间:2014-01-09 12:10:48

标签: php linux windows email postfix-mta

我正在构建一项服务,将pdf附件发送到某些电子邮件目的地。最近我发现有些人无法正常收到电子邮件: - 标题进入电子邮件正文 - 附件损坏

通过一系列测试,我得知问题可能是PHP_EOL,因为当我更改它时(从\ n到\ r \ n或反之亦然),有些人会很好地接收它,而其他人则不会“T。 是编码问题还是服务器问题?

    $separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "Convite.pdf";

// encode data (puts attachment in proper format)
$pdfdoc = $content;
$attachment = chunk_split(base64_encode($pdfdoc));

// main header
$headers  = "From: Myserver<".$from_mail.">\nBCC: suporte@myserver.com".$eol;
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed;\tboundary=\"".$separator."\"";

// no more headers after this, we start the body! //
$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;

//message
$body = "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"utf-8\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;

// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/pdf; name=\"".$filename."\"".$eol; 
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";

0 个答案:

没有答案