【发布时间】:2020-11-04 18:26:49
【问题描述】:
我正在使用 Yii framwework 和 phpmailer 发送邮件到特定 用户。我的邮件功能正常工作,但我被困在附件中 我从一个函数生成 pdf 的一部分。
这里有生成pdf数据的功能是动态的:
public function generatePdf()
{
$html = '';
$html .= '<div></div>'; //and same like this all html part.
echo $html;
//mpdf stuff will come here.
$mpdf->WriteHTML($stylesheet,1); //
$mpdf->WriteHTML($html,2);
$mpdf->Output($path.$file_name, "F");
}
此功能正常工作以生成 pdf。但是现在我想用同样的功能用邮件发送附件。我不知道如何实现。请帮助我。
我有另一个发送邮件的功能:
public function sentMail(){
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 2; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->SMTPAutoTLS = false;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
} // demo code
}
如何在我的 sendMail() 中使用 generatePdf 函数作为附件。
【问题讨论】:
标签: php email yii email-attachments