gpt4 book ai didi

php - 生成 PDF 输出并使用 phpmailer 将其发送到电子邮件

转载 作者:行者123 更新时间:2023-12-03 09:10:28 26 4
gpt4 key购买 nike

我需要生成 pdf 输出并将其发送到电子邮件,我收到的电子邮件没有附件我需要生成 pdf 输出并将其发送到电子邮件,我收到的电子邮件没有附件

require('lib/FPDF/fpdf.php'); 
require 'lib/PHPMailer/PHPMailerAutoload.php';
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'hello india');

$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = SmtpServer; // SMTP server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = SmtpUsername; // SMTP username
$mail->Password = SmtpPassword; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->From = FromEmail;
$mail->Port = 587; // SMTP Port
$mail->FromName = 'testing';

$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($emails);
$mail->AddAttachment($pdf->Output("Test Invoice.pdf","F"), '', $encoding = 'base64', $type = 'application/pdf');
return $mail->Send();

最佳答案

require('lib/FPDF/fpdf.php'); 
require 'lib/PHPMailer/PHPMailerAutoload.php';
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'hello india');
$pdf->Output("F",'./uploads/OrderDetails.pdf');
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = SmtpServer; // SMTP server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = SmtpUsername; // SMTP username
$mail->Password = SmtpPassword; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->From = FromEmail;
$mail->Port = 587; // SMTP Port
$mail->FromName = 'testing';

$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($emails);
$mail->AddAttachment("./uploads/OrderDetails.pdf", '', $encoding = 'base64', $type = 'application/pdf');
return $mail->Send();

如果您不想将文件保存到服务器,您可以直接将 pdf 输出发送到电子邮件,如下所示

    require('lib/FPDF/fpdf.php'); 
require 'lib/PHPMailer/PHPMailerAutoload.php';
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Write(5,'Hello India');

$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = SmtpServer; // SMTP server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = SmtpUsername; // SMTP username
$mail->Password = SmtpPassword; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->From = FromEmail;
$mail->Port = 587; // SMTP Port
$mail->FromName = 'testing';

$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($emails);
$mail->addStringAttachment($pdf->Output("S",'OrderDetails.pdf'), 'OrderDetails.pdf', $encoding = 'base64', $type = 'application/pdf');
return $mail->Send();

关于php - 生成 PDF 输出并使用 phpmailer 将其发送到电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42972187/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com