email - 使用 Swift 发送 HTML 电子邮件

标签 email symfony1 swiftmailer

我想使用 Swift 从我的应用程序发送一封带有 HTML 正文的自动生成的电子邮件。

这是我当前的代码:

$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);

我已经尝试使用一些特定的 Swift 方法更改电子邮件的标题内容类型,但它不起作用。

最佳答案

看:

Sending a HTML E-Mail (来自 SwiftMailer 文档)

您需要添加这一行来设置 html 内容类型:

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

或者,它可以通过在 $message->setBody() 方法上传递第二个参数来完成:
$message->setBody($this->getPartial('global/mail_partial'), 'text/html');.

关于email - 使用 Swift 发送 HTML 电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3112170/

相关文章:

git - Jenkins 电子邮件扩展插件电子邮件通知的收件人是什么?

html - 输入类型的背景图像提交到电子邮件

php - 如何在 symfony 中输出 xml?

php - Swiftmailer 不发送电子邮件(仅存储在假脱机中)

laravel swift-mailer 异常 "Expected response code 250 but got an empty response"使用 gmail smtp-relay (数据库队列驱动程序)

python - 使用 gmail smtp 从我的 python 脚本发送报告

java - 使用 Java 通过 Gmail 发送的问题

php - symfony 1.4 中使用的默认 javascript 库是什么?

symfony1 - 如何使用 symfony 和 propel 执行 "Select count..."?

php - Swift Mailer 递送状态