?
Solved

plain text messages using PHPmailer

Posted on 2009-12-18
17
Medium Priority
?
611 Views
Last Modified: 2013-12-13
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

;
0
Comment
Question by:daisydoos
  • 8
  • 3
  • 2
  • +2
15 Comments
 
LVL 11

Expert Comment

by:asafadis
ID: 26079081
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.
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 26079099
As long as $mail->IsHTML(true) is enabled, you can view the email as HTML.
0
 

Author Comment

by:daisydoos
ID: 26090301
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:daisydoos
ID: 26090313
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
0
 

Author Comment

by:daisydoos
ID: 26090401
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
0
 
LVL 11

Expert Comment

by:asafadis
ID: 26090909
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!
0
 

Author Comment

by:daisydoos
ID: 26095108
Hi asafadis,

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

Cheers,

Daisy
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 26142749
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.
0
 

Author Comment

by:daisydoos
ID: 26143818
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
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 26144004
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.
0
 

Author Comment

by:daisydoos
ID: 26144037
Hi Routinet,

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

Cheers,

Daisy
0
 

Author Comment

by:daisydoos
ID: 26144172
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
0
 
LVL 51

Accepted Solution

by:
Steve Bink earned 2000 total points
ID: 26144341
From my research this evening (not much...<30 minutes), this appears to be a known issue with Outlook.  See here:

http://www.campaignmonitor.com/blog/post/2520/testing-the-plain-text-version/

Be sure to look at the comments below the article.  I have not used Outlook in a good long time, so I'm not sure what settings are available.  You'll also have to contend with this issue across different versions, since MS likes to mix things up with each release.  The good news here is that almost all Outlook users will be viewing the HTML version of the email, so this should have a limited impact on your mail if you take care with your HTML.
0
 

Author Comment

by:daisydoos
ID: 26144451
Hi Routinet,

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

Cheers,

Daisy
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 26145381
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.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month17 days, 8 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question