2013-05-14 127 views
0

我使用Pear's Mail Mime通過SMTP Gmail從我的服務器發送電子郵件。但是,當我添加附件時,它不會顯示出來。通過Mime/SMTP Gmail服務器(PHP,PEAR)發送的郵件中缺少附件

$smtpinfo["host"] = "ssl://smtp.gmail.com"; 
$smtpinfo["port"] = "465"; 
$smtpinfo["auth"] = true; 
$smtpinfo["username"] = "xxx"; 
$smtpinfo["password"] = "xxx"; 

$headers = array(
'From' => $from, 
'To'  => $to, 
'Subject' => utf8_decode($subject) 
); 

$mime = new Mail_mime(); 

$mime->setHTMLBody($html); 

$mime->addAttachment("http://ww.url.of.a.file.that.exists.100percent.jpg", "image/jpeg"); 

$body = $mime->get(array('html_charset' => 'utf-8','charset' => 'utf-8')); 

$headers = $mime->headers($headers); 

$smtp = Mail::factory('smtp', $smtpinfo); 

$mail = $smtp->send($to, $headers, $body); 

一切正常,只是attachement是完全丟失.. 我一直在google搜索小時。我很感激任何提示..

回答

0

我的第一個想法是檢查[布爾]響應該addAttachment方法,看它是否會返回「未找到」或其它類型的指示(S)的

$fileAttached = $mime->addAttachment("http://ww.url.of.a.file.that.exists.100percent.jpg", "image/jpeg"); 
echo (!empty($fileAttached)) ? "Attached successfully!" : "Uh, Houston?"; 

我最初的想法是,它期待的是「文件」是「失水」到你的系統,而不是訪問通過http等,而且,即使它可以使用w用於HTTP訪問,您可能還希望檢查.ini文件中的allow_url_fopen以確保將它設置爲'enabled'{「On」,如果查看您的phpinfo()結果。

的 '文件' 的附加信息 -

http://pear.php.net/manual/en/package.mail.mail-mime.addattachment.php 
相關問題