Search code examples
phpmailermimeboundary

PHPmailer and boundary headers


Is it possible to add/update boundary headers via PHPmailer for the code

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

I need to add/update

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

to looks like

--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

so for the Content-Type header was added charset parameter and then added new header Content-ID

Any tips on that?


Solution

  • After further investigation it came up that

    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.

    So in my case it will be

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

    Regarding adding charset parameter to the Content-Type boundary header

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