2017-04-25 127 views
0

我使用PHP郵件發送pdf中的發票。 PDF是使用tcpdf插件attatchment生成的,不能分配到郵件我使用以下代碼 請幫助我,我該怎麼辦?使用由tcpdf生成的Phpmailer發送PDF文件

$pdf->writeHTML($html, true, false, false, false, ''); 


$pdf->Output($pdf_name, 'I'); 

$filename =$pdf_name.".pdf"; 

$pdfdoc = $pdf->Output("invoice.pdf", "S"); 
$attachment = chunk_split(base64_encode($pdfdoc)); 

        require_once('class.phpmailer.php'); 
         define('GUSER', '[email protected]'); 
         define('GPWD', 'xxx'); 
         $subject ="Instant e-Bill from for ".$hotel_name; 
         function smtpmailer($to, $from, $from_name, $subject, $body) 
         { 
          global $error; 
          $mail = new PHPMailer(); 
          $mail->IsSMTP(); 
          $mail->SMTPDebug = 1; 
          $mail->SMTPAuth = true; 
          $mail->SMTPSecure = "tls"; 
          $mail->Host ="mail.activebittechnologies.com"; 
          $mail->port =25; 
          $mail->Username = GUSER; 
          $mail->Password = GPWD;   
          $mail->SetFrom($from, $from_name); 
          $mail->Subject = $subject; 
          $mail->Body = $body; 
          $mail->AddAttachment($attachment); 
          $mail->AddAddress($to); 
          if(!$mail->Send()) { 
           $error = "Mail error: ".$mail->ErrorInfo; 
           return false; 
          } else { 
           $error = "Message sent!"; 
           return true; 
          } 
         } 

          $message ="Booking enquiry form www.hotelsinkonkan.in"; 


smtpmailer("[email protected]","[email protected]","Invoice Form hotelsinkonkan",$subject,$message); 
+1

[如何使用TCPDF與PHP郵件功能]可能重複(http://stackoverflow.com/questions/11571977/how-to-use-tcpdf-with-php-mail-function) – Synchro

回答

0

你爲什麼這樣做?

$attachment = chunk_split(base64_encode($pdfdoc)); 

PHPMailer的需要照顧的一切給你,所以你需要做的是:

$mail->AddAttachment($pdfdoc, 'invoice.pdf'); 

而且我可以從你的代碼告訴您使用的是很舊了,車和易受攻擊的版本PHPMailer的。 Get the latest,將您的代碼基於隨附的示例,並閱讀文檔。

+0

直到不​​attatching在電子郵件中記錄 – Vivek

+0

因此,請檢查返回值,仔細檢查PDF的路徑是否正確以及文件是否存在。 – Synchro