Sending an HTML email using Swift

谁说我不能喝 提交于 2019-12-20 19:41:50

问题


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(array('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.


回答1:


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');.


来源:https://stackoverflow.com/questions/3112170/sending-an-html-email-using-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!