【发布时间】:2021-11-04 12:39:59
【问题描述】:
我想在电子邮件中附加一个文件。但文件从动态视图中获取。有可能吗?
这是我在 phpmailer 中编写的代码。
$url = 'http://somewebsite.com/parameter';
$binary_content = file_get_contents($url);
if ($binary_content === false) {
throw new Exception("Could not fetch remote content from: '$url'");
}
$mail->AddStringAttachment($binary_content, "test.pdf", $encoding = 'base64', $type = 'application/pdf');
上述代码已成功附加在电子邮件中。但是pdf文件打不开还是报错。
【问题讨论】:
-
仔细检查您实际获取的是 PDF