Setting the Body Content
The body of the message – seen when the user opens the message – is specified by calling the setBody() method. If an alternative body is to be included addPart() can be used.
The body of a message is the main part that is read by the user. Often people want to send a message in HTML format (text/html), other times people want to send in plain text (text/plain), or sometimes people want to send both versions and allow the recipient to chose how they view the message.
As a rule of thumb, if you're going to send a HTML email, always include a plain-text equivalent of the same content so that users who prefer to read plain text can do so.
To set the body of your Message:
- Call the setBody() method of the Message, or specify it at the time you create the message.
- Add any alternative bodies with addPart().
If the recipient's mail client offers preferences for displaying text vs. HTML then the mail client will present that part to the user where available. In other cases the mail client will display the "best" part it can - usually HTML if you've included HTML.
Setting the Body – and adding alternative body content
//Pass it as a parameter when you create the message
$message = Swift_Message::newInstance('Subject here', 'My amazing body');
//Or set it after like this
$message->setBody('My <em>amazing</em> body', 'text/html');
//Add alternative parts with addPart()
$message->addPart('My amazing body in plain text', 'text/plain');