【问题标题】:PHPmailer and boundary headersPHPmailer 和边界标头
【发布时间】:2018-07-06 01:11:23
【问题描述】:

是否可以通过 PHPmailer 为代码添加/更新边界标头

$mail->addStringAttachment($test, 'test.txt', 'quoted-printable');

我需要添加/更新

--b1_KyZbvbrSl55hdWoQf7uUOwdfF2oGjqnCyP6rqNmlA
Content-Type: text/plain; name="test.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename=test.txt

看起来像

--b1_KyZbvbrSl55hdWoQf7uUOwdfF2oGjqnCyP6rqNmlA
Content-Type: text/plain; name="test.txt"; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename=test.txt
Content-ID: 20cca107-2625-49ce-9357-95254a59147f@127.0.0.1

所以对于Content-Type 标头添加了charset 参数,然后添加了新标头Content-ID

有什么建议吗?

【问题讨论】:

    标签: phpmailer mime boundary


    【解决方案1】:

    用于传输编码和字符集

    $mail->Encoding = 'quoted-printable';
    $mail->CharSet = 'UTF-8';
    

    对于 content-id 检查 addEmbeddedImage 方法或尝试像这样直接添加标题:

    $mail->addCustomHeader('Content-ID', '20cca107-2625-49ce-9357-95254a59147f@127.0.0.1');
    

    【讨论】:

    • 我正在寻找为每个边界而不是消息本身设置标题。
    • 嗯,有点接近了。
    【解决方案2】:

    经过进一步调查发现

    addStringEmbeddedImage 方法允许您为 附件将为您设置该标题。你可以忽略 方法名称中的“图像” - 它不关心您的内容类型 真的附上。

    所以在我的情况下是

    $mail->addStringEmbeddedImage(file_get_contents($file_name, FILE_USE_INCLUDE_PATH), $uuid, $file_name, 'base64', '', 'attachment');

    关于在Content-Type边界头中添加charset参数

    quoted-printable 传输编码是 ASCII 7 位安全的,所以默认 可以正常工作,并且不需要额外的字符集子句。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-07
      • 2019-07-25
      • 2015-09-26
      • 1970-01-01
      • 1970-01-01
      • 2015-04-02
      • 2014-05-15
      相关资源
      最近更新 更多