2014-12-30 66 views
3

我正在使用MIME smtp喲發送郵件。我的問題是郵件沒有任何附件。我想發送帶附件的pdf郵件。 我的代碼如下在MIME中添加pdf的附件smtp

$a = $fpdf->writeHTML($fpdf, true, false, true, false, '') ; 
    //$a = $fpdf->Output() ; 


    $host  = 'smtp.ample.co.in'; 
$username = '[email protected]'; 
$password = 'asa3'; 

$to = "[email protected]"; 
$from = "[email protected]"; 
$subject = "Attachments Test"; 
$filename = "test"; 

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

$smtp = Mail::factory('smtp', array('host'=>$host, 'auth'=>true, 'username'=>$username, 'password'=>$password)); 

$text = "Plain Text Email Content"; 
$html = "HTML Email Content\n"; 
//$attachment = "mail_serinv.php?tchyear=2014&tchfyear=14&tchcid=001&tninvid=105466&tcpflag=I&tcnflag=L"; 

$mime = new Mail_mime(); 
$mime -> setTXTBody($text); 
$mime -> setHTMLBody($html); 
$mime -> addAttachment($a, 'text/plain',$filename,false); 

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

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

if(PEAR::isError($mail)) { 
    echo $mail->getMessage(); 
} else { 
    echo 'Message sent'; 
} 

我搜索了很多鏈接,發現沒用。請幫我在尋找解決辦法

+0

'addAttachment'是否返回成功/失敗值?你能把我們鏈接到該方法的文檔嗎? 「假」在這裏做什麼? – halfer

+0

它顯示附件test.php與0kb ..沒有數據 – namratha

回答