2016-08-02 37 views
-3

下面是我的電子郵件發送腳本代碼,一年相同的代碼工作得很好,但現在它不發送任何電子郵件,請幫我解決這個錯誤了電子郵件未發送給「多行找到」錯誤

消息:電子郵件():在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) 
); 

回答

0

找到多個或畸形換行符你必須確保你的主機上的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)); 
+0

它可能會解決問題,但是當我添加腳本它給了我一些其他的錯誤,如爲「uid」和「編碼內容」和其他一些變量沒有定義,你能告訴我位更多關於這個,因爲大約一年前,這個腳本發送電子郵件,但我收到錯誤,這是由任何PHP升級或任何其他原因發生? –

+0

請閱讀這篇文章,因爲它確實是你的情況 - http://mindofdes.blogspot.bg/2015/07/error-with-php-mail-multiple-or.html –