【问题标题】:Sending dynamic email attachement from view in codeigniter从 codeigniter 中的视图发送动态电子邮件附件
【发布时间】: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文件打不开还是报错。

【问题讨论】:

标签: php email phpmailer


【解决方案1】:

您必须在此处对附件内容使用 base64encode。

$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'");
}
$file_content = base64encode($binary_content);
$mail->AddStringAttachment($file_content, "test.pdf", $encoding = 'base64', $type = 'application/pdf');

【讨论】:

    猜你喜欢
    • 2012-12-16
    • 1970-01-01
    • 2013-05-02
    • 1970-01-01
    • 2020-03-27
    • 2018-02-06
    • 2013-01-07
    • 2019-08-07
    相关资源
    最近更新 更多