Sending base64 emails using SWIFTMAIL

I'm just trying to get my multi-page base64 encoded emails and send via swiftmail. Here is the code that I still have:

$message = Swift_Message::newInstance("Email Template Test")
    ->setBoundary($boundary)
    ->setFrom(array('no-reply@domain.net' => 'Mailer Service'))
    ->setTo(array("a@d.com","a@b.com"))
    ->setBody($plaintext)
    ->addPart($htmlmail,"text/html");

$headers = $message->getHeaders();
$headers->addTextHeader('Content-Transfer-Encoding','base64');

$contenttype = $message->getHeaders()->get('Content-Type');
$contenttype->setValue('multipart/alternative');

As far as I can see from the documentation (which I don't find too clear), the heading Content-Transfer-Encodingis a text heading, so I should be able to set it as above. Before that, I started displaying all current headers, but was Content-Transfer-Encodingnot listed there, so I had to install it. Therefore, in the above code, I tried to install it.

, , , , . , $plaintext base64_encode($plaintext), . >

+4
1

version 5.4 . Swift_Message .

$message = \Swift_Message::newInstance("Email Template Test");
$message->setEncoder(\Swift_Encoding::getBase64Encoding());
//...

, ( 4 5) addPart. MimePart . MimePart .

$part = \Swift_MimePart::newInstance();
$part->setEncoder($message->getEncoder());
$part->setBody($htmlmail, 'text/html');
$message->attach($part);

Content-Type: multipart/alternative; boundary=****, border charset Content-Transfer-Encoding: base64.

:

var_dump($message->toString());

string 'Message-ID: <2f48c04910b97f730834e92f268d3410@example.com>
Date: Thu, 14 Jan 2016 20:45:30 +0000
Subject: Email Template Test
From: Mailer Service <no-reply@domain.net>
To: a@d.com, a@b.com
MIME-Version: 1.0
Content-Type: multipart/alternative;
 boundary="_=_swift_v4_1452804330_b0a47ad936ba98d2f513294958a235d0_=_"


--_=_swift_v4_1452804330_b0a47ad936ba98d2f513294958a235d0_=_
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64

VGhpcyBpcyBhbiBodG1sIG1lc3NhZ2U=

--_=_swift_v4_1452804330_b0a47ad936ba98d2f513294958a235d0_=_
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64

VGhpcyBpcyBhIHRleHQgbWVzc2FnZQ==

--_=_swift_v4_1452804330_b0a47ad936ba98d2f513294958a235d0_=_--
' (length=751)
+2

Source: https://habr.com/ru/post/1536072/


All Articles