【问题标题】:How can I Attach a .eml File Using PHPMailer?如何使用 PHPMailer 附加 .eml 文件?
【发布时间】:2021-06-22 05:33:42
【问题描述】:

我正在尝试将 .eml 文件附加到我在 PHPMailer 中发送的电子邮件中。我现在正在这样做:

$mail->addStringAttachment("/var/www/virtual/xxx.xxx.com/html/test_sample_message.eml", 'test.eml', 'base64', 'message/rfc822');

它确实附加了一个 .eml 文件,但它始终是空的。另外,我尝试这样做:

$mail->addStringAttachment($body, 'test.eml', 'base64', 'message/rfc822');

如果我这样做,结果相同(电子邮件文件已附加,但它是空的)。

我在这里做错了什么? 谢谢。

【问题讨论】:

  • 为什么不使用addAttachment?根据phpmailer.github.io/PHPMailer/classes/…,对于 addStringAttachment 它说This method can be used to attach ascii or binary data, such as a BLOB record from a database - 即一串数据,而不是文件。 addAttachment 用于附加现成的文件。
  • 嗨 ADyson - 我尝试使用 addAttachment,结果相同:附加了一个空白 eml 文件。有任何想法吗? (不知道是否有区别,但我什至将 eml 文件的权限更改为尽可能少的限制。)
  • 检查任一调用的返回值,不要假设它正在工作。
  • @Synchro - 你指的是 addAttachment 的结果吗?我这样做了 - $val = $mail->addAttachment("/var/www/virtual/beta.phishingbox.com/html/test_sample_message.eml"); print_r($val);退出(“出”); - 它返回 true。
  • 在这种情况下,我建议设置一个断点并检查调用 send() 后读取文件时发生的情况。还要检查 SMTP 脚本(设置 SMTPDebug = 2),这样您就可以准确地看到发送的内容。

标签: php phpmailer eml


【解决方案1】:

删除代码:函数_mime_types($ext = '')中的'eml' => 'message/rfc822'

然后使用addAttachment()

【讨论】:

    【解决方案2】:

    这成功了:

    $mail->addStringAttachment($body, 'Original Email.eml', 'base64', 'application/octet-stream');
    

    【讨论】:

      猜你喜欢
      • 2013-08-07
      • 2013-03-15
      • 2020-04-27
      • 2015-02-08
      • 2012-02-25
      • 1970-01-01
      • 2021-09-10
      • 2011-08-31
      相关资源
      最近更新 更多