Daan
Daan

Reputation: 7925

Send HTML mail with fallback to plain text mail via Swiftmailer

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

Upvotes: 1

Views: 1734

Answers (1)

Daan
Daan

Reputation: 7925

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

Upvotes: 2

Related Questions