HTML vs Plain text as body in email
Asked Answered
G

1

23

When creating a Swift_Message you can have both a plain text and an html version of the email. You set one as the body, and then you add the other one as a part.

What is the difference if I set the HTML version as body and plain text as part, and the other way around?

$html_as_body = Swift_Message::newInstance()
    ->setSubject($subject)
    ->setBody($html, 'text/html')
    ->addPart($plain, 'text/plain');

$plain_as_body = Swift_Message::newInstance()
    ->setSubject($subject)
    ->setBody($plain, 'text/plain')
    ->addPart($html, 'text/html');

And by difference, I mean what kind of difference will it have in email readers and such?

Goldshlag answered 11/6, 2012 at 19:24 Comment(0)
A
13

There should be no difference, if only Swift_Message follows official RFC for mail compose, which (AFAIK) strictly sets that plain-text message should be default (first, body) and eventually followed by HTML version.

Make some tests, i.e. sent the same e-mails in both configurations and see in receiving client what is the source of your message.

If you see any difference, then in IMHO you should definitely send plain text body (first) and HTML version last. As even nowadays there are many simple mail clients, which will simple ignore / not properly recognize HTML version. So, if you put it as first, there is a chance that whole message will be unreadable for the receiver.

Ascend answered 21/6, 2012 at 11:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.