通过Swiftmailer发送HTML邮件,并回退为纯文本邮件


Send HTML mail with fallback to plain text mail via Swiftmailer

如何使用PHP Swiftmailer将HTML邮件回退为纯文本邮件?

在Swiftmailer中创建一条消息,并使用setBody()函数设置邮件的文本/纯文本版本,使用addPart()函数设置电子邮件的文本/html版本(第二个参数为text/html):

$message = Swift_Message::newInstance()
  ->setSubject('Your subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
  ->setBody('Here is the message itself')
  ->addPart('<p>Here is the message itself</p>', 'text/html')
  ;

签出源:http://swiftmailer.org/docs/messages.html