php - 如何在电子邮件中发送嵌入的pdf
问题描述
我正在尝试在电子邮件中嵌入 pdf。不是链接。我的邮件功能正在运行,我可以回显 pdf,但 pdf 没有出现在电子邮件中。这是我到目前为止所拥有的:
邮件功能:
function mailerExpressBlueHostSWAGpdf(array $mailInputs){
chdir('../');
require_once '../includes/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsMail();
$mail->SetFrom('swag@sustainablewestonma.org');
$mail->addAddress($mailInputs['addAddress']);
$body = $mailInputs['body'] ;
$mail->Subject = "SWAG Fall Newsletter" ;
$mail->Body = $body;
$mail->IsHTML(true);
$mail->ContentType="text/HTML";
if(!$mail->send()) {
// echo 'mail not sent <br>' ;
$mail->ClearAddresses();
return 'Message could not be sent.' . 'Mailer Error: ' . $mail->ErrorInfo;
}else{
// echo 'mail sent 2<br>';
echo $body;
$mail->ClearAddresses();
return 'Message has been sent';
}
}
电子邮件的 HTML (email-embed-pdf.html)
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<div>
<iframe src="https://www.sustainablewestonma.org/newsletter-fall2021.pdf"></iframe>
</div>
</body>
</html>
发送电子邮件的程序 (embed-pdf.php)
<?php
require ("../../includes/functions.php");
require ("../../includes/newConstants.php");
$body = file_get_contents('../../vhtml/email-embed-pdf.html');
$mailerInputs['body'] = $body;
$mailerInputs['addAddress'] = "abc123@gmail.com";
mailerExpressBlueHostSWAGpdf($mailerInputs);
?>
解决方案
推荐阅读
- java - 是否可以将kafka消费者寻找到主题分区的开头并再次轮询所有记录
- python - 将 url 从浏览器拖放到文本字段(tkinter 或 kivy)
- hyperledger-fabric - 事务处理器功能 - 我如何知道何时提交/认可数据
- python - 在列表列表中查找最常见的元素
- react-native - React Native 和 Redux Persist 不将状态保存到持久存储
- java - 使用 Java 8 流 API 将列表扁平化为列表
- xml - Xpath 意外输出
- angular - angular cli 7.1 无法创建新项目,架构验证错误
- html - 旋转木马在 Angular 6 中的 mat-tab 内不起作用
- javascript - 在图表工具提示插件中显示日期(DD-MM-YYY)格式?