Forum Moderators: coopster

Message Too Old, No Replies

Hybrid PHP Mail (text and html)

         

NeilsPHP

9:54 pm on Apr 18, 2009 (gmt 0)

10+ Year Member



I am trying to use php scripts to send out autoresponders kind of emails (newsletters,membership offers etc).
I have been testing both html and text formats but no luck with all mail clients..some work on yahoo,gmail or hotmail but not on AOL.(AOL is JUST not getting emails at all..strange).
I want to be able to compose one hybrid kind of email that will give freedom to mail client to choose weather it likes text or html(as per user pref) and deliver.I am using-

$headers .= "MIME-Version: 1.0\r\n";
$headers .= "\r\nContent-Type: Multipart/alternative;

type of scripting but am not having any luck.
Can somebody help with any better ideas ?

(I wish I can use if else clause..but don't know if there is a way to find out the 'choice' of mail clients ? )

dreamcatcher

11:13 am on Apr 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would recommend something like PHPMailer, which has all the functionality you need for sending HTML & plain text messages.

dc

rocknbil

3:50 pm on Apr 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A couple ideas . . .

...give freedom to mail client to choose weather it likes text or html(as per user pref)

A little confused, user pref on your system or their preferences? If on your system, easy, when you send, swap between plain text or HTML, but if on their system - I have heard and seen MANY solutions that purport to allow the mail client to decide whether to display text or HTML and have never seen it work under all clients (which doesn't mean it doesn't exist . . . . just all the ones I've tried have failed.)

I want to be able to compose one hybrid kind of email

However, this will always work, it just has a little caveat for text-only clients. Output the text/html headers like you normally do. Text clients ignore or entity-ize HTML, right? Based on that, your body now becomes

<!--
If you are seeing this message, your mail program only accepts plain text messages. For a better experience, please configure your mail program to accept html messages from this web site. You may ignore any html code you see below.

THIS IS YOUR PLAIN TEXT BODY

ETC.
-->
<html><head><title>My Subject</title></head><body>
<p>THIS IS YOUR HTML BODY</p>
<p>ETC.</p>
</body>
</html>

The HTML version sees the comment as . . . a comment. Not visible to the end user.

The "caveat" is that if the mail client turns the HTML into entities, you have all this code at the bottom, hence the opening message for text only clients.

If you output html, make SURE it has an opening/closing html and body tag, just like a web page - otherwise SpamAssassin will add to your score: "HTML message, but no html tag . . . "

(AOL is JUST not getting emails at all..strange).

This is probably completely unrelated. Search around here for threads on email delivery, it could be DNS issues, no SPF records, you're hosted on a server that's in the RBL's, lots of things, most of them not related to PHP at all.

NeilsPHP

4:41 pm on Apr 19, 2009 (gmt 0)

10+ Year Member



rocknbil,
A good idea that i can use until i learn more about MIME Version & Content-Type: Multipart/alternative ways of doing it.
thnks

subhankar ray

10:24 pm on Apr 19, 2009 (gmt 0)

10+ Year Member



The following code worked for me
*************************************
$body_text = " your text";

$body = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$body_text . "\n\n";

$body_html = "
<html>
<body>

<TABLE bgColor=white border=0 bgproperties=fixed borderColor=#000000 cellPadding=0 cellSpacing=0
width=640>
<tr><td>
your text
<p>

</td>
</tr>
</table>
</body>
</html>
\n\n";

$body .= "--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$body_html . "\n\n";

mail($email, 'subject', $body, $header );