Tearing my hair out - HTML in email

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
alimax
Forum Newbie
Posts: 6
Joined: Fri Dec 06, 2002 6:30 am

Tearing my hair out - HTML in email

Post by alimax »

Hi all

I am using the mail() function to generate emails all the time, I never have a problem with it. Now all emails I generate are not parsing the HTML, I have tried every combination of headers imaginable but still they appear in the mail and the HTML is not parsed, the main header I never neglect to include is $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

has anyone got any ideas where this is going wrong, my mail client receives HTML mail okay.

thanks :roll:
User avatar
alimax
Forum Newbie
Posts: 6
Joined: Fri Dec 06, 2002 6:30 am

Post by alimax »

the version below works fine but has no HTML if I insert <a> tags around QUALIFY NOW and create a hyperlink to the site, all efforts of mine print <a href="www.Thesite.com/qualify">QUALIFY NOW</a> in the email, and yes before you ask I am escaping the quotes with \ so pse pse someone help...while I still have some hair

// build the friend's email...

$to = "$email";

$subject = "BIOTRAX ELIGIBILITY TEST $sender";

$body ="BIOTRAX ELIGIBILITY TESTING\r\n\r\nMessage from $sender: $note\r\n\r\nMAKE BETTER USE OF YOUR SPARE TIME.\r\n\r\nREGISTERING WITH US, THE ONLY UNITY OF VOLUNTEERS IN THE WORLD\r\n\r\nSEE IF YOU QUALIFY NOW\r\nBY CLICKING ON THIS LINK: http://www.Thesite.com/qualify\r\n";
$message="$body";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers = "From: $sender <$sender_email>\n";
$headers .= "Reply-To: <$sender_email>\n";
$headers .= "Return-Path: <$sender_email>\n";

// end email building..

// send the mail..

mail($to,$subject,$message,$headers);
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

$headers = "From: $sender <$sender_email>\n";
you forgot the .
So there is no mime-type after this statement anymore ;)
User avatar
alimax
Forum Newbie
Posts: 6
Joined: Fri Dec 06, 2002 6:30 am

Post by alimax »

Thanks for that, that defo would screw it up but having fixed that (and that wasn't in all of my efforts it is a recent cutnpaste "incident") I get this as my resulting email with the <a> tags showing:

Content-type: text/html; charset=iso-8859-1
From: Ali <ali@hooverburger.co.uk>
Reply-To: <ali@hooverburger.co.uk>


BIOTRAX ELIGIBILITY TESTING

Message from Ali: This had better work

MAKE BETTER USE OF YOUR SPARE TIME.

REGISTERING WITH US, THE ONLY UNITY OF VOLUNTEERS IN THE WORLD,
IS VERY REWARDING.

SEE IF YOU <a href="www.Thesite.com/qualify">QUALIFY NOW</a>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I use this order of statements

Code: Select all

$headers = "MIME-Version: 1.0\n";
$headers .= "From: $sender <$sender_email>\n";
$headers .= "Reply-To: <$sender_email>\n";
$headers .= "Return-Path: <$sender_email>\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
and it's working as expected (in outlook express and mozilla)
User avatar
alimax
Forum Newbie
Posts: 6
Joined: Fri Dec 06, 2002 6:30 am

Post by alimax »

I love you, why was this so different? I have not been aware of any need to order the headers and if such a need does exist does this not need pointing out somewhere?

Thanks a million :D
Post Reply