2014-11-05 85 views
0

當我運行此我得到以下錯誤:解析錯誤:語法錯誤,以W意外的文件結尾:\ XAMPP \ htdocs中___上線\ phpmail.php 85爲什麼我不斷收到最後一行代碼的錯誤信息?

<?php 
// Setting a timezone, mail() uses this. 
date_default_timezone_set('America/New_York'); 
    // recipients 
$to = "[email protected]" . ", " ; // note the comma 
$to .= "[email protected]"; 

    // subject 
$subject = "Test for Embedded Image & Attachement"; 

// Create a boundary string. It needs to be unique 
$sep = sha1(date('r', time())); 

// Add in our content boundary, and mime type specification: 
$headers .= 
    "\r\nContent-Type: multipart/mixed; 
    boundary=\"PHP-mixed-{$sep}\""; 

// Read in our file attachment 
$attachment = file_get_contents('attachment.zip'); 
$encoded = base64_encode($attachment); 
$attached = chunk_split($encoded); 

// additional headers 
$headers .= "To: You <[email protected]>, 
      We <[email protected]>\r\n"; 
$headers .= "From: Me <[email protected]>\r\n"; 
$headers .= "Cc: [email protected]\r\n"; 
$headers .= "Bcc: [email protected]\r\n"; 

$inline = chunk_split(base64_encode(
      file_get_contents('mypicture.gif'))); 

// Your message here: 
$body =<<<EOBODY 
--PHP-mixed-{$sep} 
Content-Type: multipart/alternative; 
       boundary="PHP-alt-{$sep}" 

--PHP-alt-{$sep} 
Content-Type: text/plain 

Hai, It's me! 


--PHP-alt-{$sep} 
Content-Type: multipart/related; boundary="PHP-related-{$sep}" 
, 
--PHP-alt-{$sep} 
Content-Type: text/html 

<html> 
<head> 
<title>Test HTML Mail</title> 
</head> 
<body> 
<font color='red'>Hai, it is me!</font> 
Here is my picture: 
    <img src="cid:PHP-CID-{$sep}" /> 
</body> 
</html> 

--PHP-related-{$sep} 
Content-Type: image/gif 
Content-Transfer-Encoding: base64 
Content-ID: <PHP-CID-{$sep}> 

{$inline} 
--PHP-related-{$sep}-- 

--PHP-alt-{$sep}-- 

--PHP-mixed-{$sep} 
Content-Type: application/zip; name="attachment.zip" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

{$attached} 

--PHP-mixed-{$sep}-- 
EOBODY; 

// Finally, send the email 
mail($to, $subject, $body, $headers); 
?> 

那爲什麼我得到這個錯誤?我從這裏的教程得到了這段代碼:www.phpeveryday.com/articles/PHP-Email-Using-Embedded-Images-in-HTML-Email-P113.html

+0

檢查此行否並修復引用 – 2014-11-05 12:48:31

+1

您沒有正確結束HEREDOC。在該行的'EBODY'之前不應該有空格。您應該[啓用錯誤報告](http://stackoverflow.com/a/6575502/1438393)來查看那種有用的錯誤消息。 – 2014-11-05 12:50:08

+0

您是否閱讀過本教程的評論?他們擰它! – 2014-11-05 12:52:05

回答

0

因爲你的郵件功能仍然在EOBODY。

也請嘗試尋找另一種解決方案,或者創建自己的郵件,因爲我剛剛在這個頁面看了一些評論:

  • 我想,這一定是最壞的教程之一有史以來,沒有按不工作

  • 這是一個愚蠢的狗屎。

  • ü白癡

等...我同意。

還有很多像這樣的好教程。使用PHPMailer。

+0

謝謝,是的,你是對的。該教程是可愛的。 – KieranH19 2014-11-05 13:17:45

相關問題