2013-07-16 16 views
0

我正在使用PHPmailer爲客戶發送電子優惠券。我想向用戶發送一個動態的html文檔作爲正文,但是當我參考這個文件時,我得到一個錯誤。PHPMailer - 無法加載MsgHTML

我的代碼如下:

$sessionid = '12345'; 
$cid = '98765'; 
require('class.phpmailer.php'); 
$bodytext1 = "Your Evoucher is attached for ".$row_checkout['name']; 
$email = new PHPMailer(); 
$email->From  = '[email protected]'; 
$email->FromName = 'xxx.com'; 
$email->Subject = 'Your e-voucher for '.$row_checkout['name']; 
$email->AddAddress($row_user['email']); 
$email->MsgHTML(file_get_contents('mail.php?sid='.$sessionid.'&cid='.$cartid)); 

$file_to_attach = $sessionid.'/'.$bookingid.'.pdf'; 

$email->AddAttachment($file_to_attach , $bookingid.'.pdf'); 
return $email->Send(); 

當我運行它,我得到以下錯誤:

Warning: file_get_contents(mail.php?sid=12345&cid=98765) [function.file-get-contents]: failed to open stream: No such file or directory in /home4/mission/public_html/xxx.com/evoucher/new/createandmail.php on line 93 

但是,如果我不把這些變量中的URL,即

$email->MsgHTML(file_get_contents('mail.php')

發送罰款,但帶有不正確的領域的身體秒。

有什麼建議嗎?

回答

0

您必須使用完整的URL(包含協議:http://..)或使用文件名。 mail.php?sid...不是一個文件名 - 這是一個相對uri,它是apache的handeld。如果你使用file_get_contents('mail.php'),你發送原始的php文件,這可能不是你想要的。

您也可以嘗試,而不是使用file_get_contents('http://server.com/mail.php?...'

0

您無法將GET參數添加到要加載的文件。 file_get_contents會加載你的php文件內容 - 不是腳本會產生什麼內容。

如果啓用了URL的fopen您可以添加完整的URL地址mail.php,但它並不總是最好的主意,也可以包括這mail.php到您的代碼(但是第一個變化_GET到內部變量)

0

我建議使用cURL則內容應正確獲取的mail.php的獲取內容的virtual功能。 (或使用file_get_contents中的完整url)

0

您可以包含文件並使用當前腳本中的變量(會話和購物車ID)。如果您在包含的PHP腳本中設置HTML正文,則不會有任何問題。