Send HTML mail with fallback to plain text mail via Swiftmailer
Asked Answered
K

1

1

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

Klos answered 30/3, 2015 at 11:55 Comment(0)
K
2

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('[email protected]' => 'John Doe'))
  ->setTo(array('[email protected]', '[email protected]' => '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

Klos answered 30/3, 2015 at 11:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.