使用Swift发送HTML电子邮件 [英] Sending an HTML email using Swift
本文介绍了使用Swift发送HTML电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我现在的代码:
$ message = Swift_Message :: newInstance()
- > setFrom(array(willummy1@test.com'=>'John Doe '))
- > setTo('dymmy2@test.com')
- > setSubject('some subject');
$ message-> setBody($ this-> getPartial('global / mail_partial'));
$ this-> getMailer() - > send($ message);
我已经尝试使用一些特定的Swift方法来更改电子邮件的头部Content-type它不工作。
解决方案
请参阅:
发送HTML电子邮件(来自SwiftMailer文档)
您需要添加此行来设置html内容类型:
$ message- >的setContentType( text / html的);
或者,可以通过在$ message-> setBody()方法传递第二个参数:
$ message-> setBody($ this-> getPartial('global / mail_partial'),'text / html' );.
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.
解决方案
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');.
这篇关于使用Swift发送HTML电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文