我正在使用PHP邮件程序以pdf格式发送发票。使用tcpdf插件生成的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', 'sagar@example.com');
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("hotelinkonkan@gmail.com","billing@hotelinkonkan.com","Invoice Form hotelsinkonkan",$subject,$message);
答案 0 :(得分:0)
你为什么这样做?
$attachment = chunk_split(base64_encode($pdfdoc));
PHPMailer为您完成所有这些工作,所以您需要做的就是:
$mail->AddAttachment($pdfdoc, 'invoice.pdf');
此外,我可以从您的代码中了解到您使用的是一个非常旧的,错误且易受攻击的PHPMailer版本。 Get the latest,将您的代码基于随其提供的示例,并阅读文档。