PHPmailer 和边界 headers

PHPmailer and boundary headers

是否可以通过 PHPmailer 为代码 add/update 设置边界 headers

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

我需要add/update

--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 header 添加了 charset 参数,然后添加了新的 header Content-ID

有什么建议吗?

对于 transfer-encoding 和字符集

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

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

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

经过进一步调查发现

The addStringEmbeddedImage method lets you set a cid for the attachment which will set that header for you. You can ignore the "image" in the method name - it doesn't care what type of content you attach really.

所以在我的情况下会是

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

关于将 charset 参数添加到 Content-Type 边界 header

quoted-printable transfer encoding is ASCII 7bit safe, so the default will work fine and it doesn't need an extra charset clause.