Send HTML mail with fallback to plain text mail via Swiftmailer

倾然丶 夕夏残阳落幕 提交于 2019-12-25 08:48:03

问题


How can you send HTML mail with a fallback to plain text mail with PHP Swiftmailer?


回答1:


Create a message in Swiftmailer and use the setBody() function to set the text/plain version of your mail and use the addPart() function to set the text/html version of your email (with second parameter 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')
  ;

Checkout the source: http://swiftmailer.org/docs/messages.html



来源:https://stackoverflow.com/questions/29345589/send-html-mail-with-fallback-to-plain-text-mail-via-swiftmailer

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