问题
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