Link to home
Start Free TrialLog in
Avatar of daisydoos
daisydoos

asked on

plain text messages using PHPmailer

Hi,

I use PHPmailer to send out mail messages. Have an HTML message, and want to produce a text equivalent like so:

$html = "<p>some content</p>"
$mail->Body = $html;

$text = "some content\n\n";
$mail->AltBody = $text;

i usually set $mail->IsHTML(true)

The HTML message is fine if I set up Outlook to accept HTML emails. I then changed my settings in Outlook to read all mail in plain text.

The problem is that when the message is sent Outlook is reading the HTML message not the text equivalent...I thought that setting $mail->AltBody = $text would mean that Outlook would read the right message....

Am I doing something wrong? How can I ensure that Outlook reads the correct message?

Cheers,

Daisy

;
Avatar of asafadis
asafadis
Flag of United States of America image

2 things to look for:
  1. To view your emails in plain-text, the option is not in:

    Tools > Options > Mail Format > Message Format
    This is only for outgoing mail.

    For incoming mail, the option to read plain-text is in:
    Tools > Trust Center > E-mail Security > Read as Plain Text

  2. Keep in mind that once Outlook receives an email as HTML, it stays that way, regardless of whether you switch the message format.  You would have to send the email again, once you've changed Outlook to read messages in plain text.
Avatar of Loganathan Natarajan
As long as $mail->IsHTML(true) is enabled, you can view the email as HTML.
Avatar of daisydoos
daisydoos

ASKER

Hi asafadis,

I changed the settigns in tools > trust center. I sent the message to Outlook when I had changed the settings; I didnt chage the settings then try to view the message as plain text.

logudotcom: this doesnt answer my question.

Cheers,

Daisy
HI,

Just tested it again - defintely not working as expected. Outlook is set to read messages as plain text through the trust center. The email being received is the HTML version in PHPmailer - this is not what should be happening - Outlook should be reading the text equivalent should it not?

Any help much appreciated!

Daisy
Hi again,

Looking at the headers of an email I have received as text, they include:

Content-Type: multipart/alternative;
      boundary="b1_d131fd14c363ee55cb59af57268a9769"

This clearly shuold read Content-Type: text/plain;

Even if I set isHTML(false) (which I dont want to do as I do want people to be able to receive HTML emails if they want), the message headers still read Content-Type: multipart/alternative;  !!!!!

Cheers,

Daisy
The content-type in the header is fine.  "multipart/alternative" allows the email to have both a HTML and a plain-text version embedded into 1 email.
Outlook should be able to distinguish them and process them separately... that's the part I'm still trying to wrap my head around!
Hi asafadis,

Many thanks for getting back to me. Please let me know if you get a solution!

Cheers,

Daisy
I recommend you try a different email client for testing.  This will help you determine if it is a protocol issue or a client issue.
Hi Routinet,

Thanks for your comment - do you know this will work in another client? If so, which one would you recommend I test with? However, even if the code works in a different client, I'm not sure that's going to make me happy when the vast majority of people use Outlook!

Cheers,

Daisy
I was not recommending this as a solution, but more as a method to determine where you should concentrate your efforts.  As implied by asafadis, multi-part messages are part of the protocol.  If Outlook is deciding to deviate from the 'expected' functionality, that would not surprise me at all.

I use Thunderbird for my mail client, and it easily switches between HTML and plain-text versions of the same email.  I'm also aware of Eudora, and Entourage on Mac.  You can also Google for "email client" to get a quick list of the most popular.

If it shows up properly in other clients, then it is likely a functionality issue in Outlook - one that might *possibly* be addressed through configuration.  If it does not show up properly in other clients, then the format of your message is probably incorrect in some minor way.

You can also try a different mailer class to see if that affects the results.  I use a slightly modified version of HTMLMimeMail (http://www.phpguru.org/static/mime.mail.html) with my own development projects.  IMHO, though, I am more willing to look at Outlook for behavioral deviations than an open-source, publicly-vetted class.
Hi Routinet,

Many thanks for getting back to me - I'll look into the options and get back to you.

Cheers,

Daisy
Hi,

I have tested with Thunderbird, and it works - when I change the settings to read mail as plain text, the correct text equivalent of the message is read..... that's great, but do we have any idea what to do about Outlook????

Cheers,

Daisy
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Routinet,

Many thanks for looking into this. I'll have a look at the article.

Cheers,

Daisy
Just adding a small comment. I use htmlMimeMail5 from phpguru.org. Similar in many aspects to other mailing classes.

The option to view messages as plain text really means view the message as unformatted text. When I look at messages I've created (which include the plain text alternative message), the message displays as text but with a header saying that the message has been converted to plain text. Just like the messages in the spam folder.

I believe that mail agents are expected to display the alternative which provides the greatest level of detail.

Using alternative parts allows the mail agent to have a choice.

Whereas non Outlook agents allow you to force the lowest format (plain text), Outlook doesn't.

As you've seen from the article.