下面是我的电子邮件发送脚本的代码,一年相同的代码工作正常,但现在它没有发送任何电子邮件,请帮我解决这个错误
消息:mail():在additional_header中找到多个或格式错误的换行符
TestA
答案 0 :(得分:0)
您必须确保主机上的MTA(邮件传输代理)不是QMAIL,因为已知用CRLF替换LF。
然后,您必须将所有标题移动到mail()
的第4个参数,并将电子邮件的正文移动到mail()
的第3个参数中。像这样:
$encoded_content = chunk_split( base64_encode( $variables['pdfFileContents'] ));
$uid = md5( time() );
$fileName = str_replace( " ", "_", $variables['emailContains'] );
$fileName .= ".pdf";
$headers = array();
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'From: cashxcash.com<'.$sender.'>';
$headers[] = 'Content-Type: multipart/mixed; boundary="'.$uid.'"';
$body = 'This is a multi-part message in MIME format.
--'.$uid.'
Content-type:text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit
--'.$uid.'
Content-Type: application/octet-stream; name="'.$fileName.'"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="'.$fileName.'"
';
$body.= $encoded_content; // Dump file
$len = strlen($encoded_content);
if(!($encoded_content{$len-2} == "\r" AND $encoded_content{$len-1} == "\n")) $body.= "\r\n";
$body.= '--'.$uid.'--'; //End boundary
return mail($reciever,$variables['emailContains'].' Report from Cashxcash!',$body, implode("\r\n", $headers) );