开发者

Sending an HTML email using Swift

开发者 https://www.devze.com 2023-01-04 11:40 出处:网络
I would like to send an auto-generated email with HTML body from my application using Swift. Here is my current code:

I would like to send an auto-generated email with HTML body from my application using Swift.

Here is my current code:

$message = Swift_Message::newInstance()
                ->setFrom(a开发者_运维百科rray('dummy1@test.com' => 'John Doe'))
                ->setTo('dymmy2@test.com')
                ->setSubject('some subject');

            $message->setBody($this->getPartial('global/mail_partial'));

            $this->getMailer()->send($message);

I had already tried to change the header Content-type of the email message using some specific Swift methods but it is not working.


See:

Sending a HTML E-Mail (from SwiftMailer Docs)

You need to add this line to set html content-type:

$message->setContentType("text/html");

Alternatively, it can by done passing a second argument on the $message->setBody() method:

$message->setBody($this->getPartial('global/mail_partial'), 'text/html');.
0

精彩评论

暂无评论...
验证码 换一张
取 消