【问题标题】:Email is not sending giving "Multi line found" error [duplicate]电子邮件未发送“发现多行”错误[重复]
【发布时间】:2016-08-02 10:07:52
【问题描述】:

下面是我的电子邮件发送脚本的代码,一年了同样的代码运行良好,但现在它没有发送任何电子邮件,请帮我解决这个错误

消息:mail():在 Additional_header 中发现多个或格式错误的换行符

$encoded_content = chunk_split( base64_encode( $variables['pdfFileContents'] ));

$uid = md5( time() );

$fileName = str_replace( " ", "_", $variables['emailContains'] );
$fileName .= ".pdf";

////// attachment header ///////////////////////////////
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "From: cashxcash.com<{$sender}>";
$headers[] = "Content-Type: multipart/mixed; boundary=\"{$uid}\"";
$headers[] = "This is a multi-part message in MIME format.";
$headers[] = "--{$uid}";
$headers[] = "Content-type:text/plain; charset=iso-8859-1"; // Set message content type
$headers[] = "Content-Transfer-Encoding: 7bit";
$headers[] = ""; // Dump message
$headers[] = "--{$uid}";
$headers[] = "Content-Type: application/octet-stream; name=\"{$fileName}\""; // Set content type and file name
$headers[] = "Content-Transfer-Encoding: base64"; // Set file encoding base
$headers[] = "Content-Disposition: attachment; filename=\"{$fileName}\""; // Set file Disposition
$headers[] = $encoded_content; // Dump file
$headers[] = "--{$uid}--"; //End boundary

return mail(
    $reciever,
    "{$variables['emailContains']} Report from Cashxcash!",
    "", 
    implode("\r\n", $headers)
);

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    您必须确保主机上的 MTA(邮件传输代理)不是 QMAIL,因为众所周知,它会将 LF 替换为 CRLF。 然后,您必须将所有标题移动到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) );
    

    【讨论】:

    • 它可能会解决问题,但是当我添加你的脚本时,它给了我一些其他错误,如 'uid' 和 'encode-content' 以及一些其他变量没有定义,你能告诉我更多关于这是因为大约一年前这个相同的脚本正在发送电子邮件,但我收到错误,这是由任何 PHP 升级或任何其他原因发生的吗?
    • 请阅读这篇文章,因为这正是你的情况 - mindofdes.blogspot.bg/2015/07/…
    猜你喜欢
    • 1970-01-01
    • 2017-12-09
    • 2015-10-09
    • 1970-01-01
    • 1970-01-01
    • 2020-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多