Sending HTML mail

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

mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Sending HTML mail

Post by mjseaden »

Dear All,

I'm programming my sendmail form on my company website to send a standardised formatted e-mail with company logo and signature. However, some e-mail reading systems don't support HTML e-mails - is there any general rule to follow regarding sending HTML, or any way of detecting if the destination address can read HTML email (a longshot I know, but you never know).

Many thanks

Mark
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

phpmailer is what you want...
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Sending HTML mail is very dicey, as most anti-spam filters tag email consisting of only html very high. After that, it's very hard to not get tagged as SPAM. IMHO, I'd forget about the HTML email and just send a text email.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

pickle wrote:Sending HTML mail is very dicey, as most anti-spam filters tag email consisting of only html very high. After that, it's very hard to not get tagged as SPAM. IMHO, I'd forget about the HTML email and just send a text email.
In my experience that's not the case and, thinking about it, spam-filter live from being as precise as can be when it comes to spam. Thus, filtering because of a content-type would make no sense.
In fact, even most private emails I receive are HTML.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

I don't know about you, but I'm referring to server-based spam filters, such as Spam-Assasin, or Gee-Whiz. I know for a fact that an email consisting entirely of HTML gets an email flagged high as possible SPAM, although it doesn't guarantee. Client side spam filters might act differently though.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Hi

I've actually done the HTML mailing part myself customised. I've just send an e-mail with HTML code, with subject/body/company address text all taken from external variables and inserted into the message text.

My HTML e-mail works exactly as planned from my hotmail account, but when I look on Outlook, it comes up as text (just plain text HTML code) - despite the fact that it has <HTML></HTML> tags as required.

Any ideas?

Mark
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

might be malformed html headers in the code...hard to say without looking at the code you use to send the email...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you probably need the content-type in the headers..
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

feyd, can you clarify?
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

why doesn't anybody google any mroe?

Code: Select all

/* To send HTML mail, you can set the Content-type header. */
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mail() wrote:

Code: Select all

<?php
/* recipients */
$to  = "mary@example.com" . ", " ; // note the comma
$to .= "kelly@example.com";

/* subject */
$subject = "Birthday Reminders for August";

/* message */
$message = '
<html>
<head>
 <title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
 <tr>
  <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
 </tr>
 <tr>
  <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
 </tr>
 <tr>
  <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
 </tr>
</table>
</body>
</html>
';

/* To send HTML mail, you can set the Content-type header. */
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";                                // <-------- HERE

/* additional headers */
$headers .= "To: Mary <mary@example.com>, Kelly <kelly@example.com>\r\n";
$headers .= "From: Birthday Reminder <birthday@example.com>\r\n";
$headers .= "Cc: birthdayarchive@example.com\r\n";
$headers .= "Bcc: birthdaycheck@example.com\r\n";

/* and now mail it */
mail($to, $subject, $message, $headers);
?>
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

lostboy - I would Google, but that's a pretty general search ('content-type headers')...
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Thanks lostboy and Feyd.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

pickle wrote:I don't know about you, but I'm referring to server-based spam filters, such as Spam-Assasin, or Gee-Whiz. I know for a fact that an email consisting entirely of HTML gets an email flagged high as possible SPAM, although it doesn't guarantee. Client side spam filters might act differently though.
So am I. I am no expert on Spam-filters, but flagging an email as spam simply because its HTML would pretty much defeat the purpose of spam-filtering to my mind.
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

patrik,

I have to mention that as soon as I placed the HTML headers on my e-mails, my Hotmail automatically placed it in my junkmail inbox. If I don't place the HTML headers on there (still with HTML code), it still displays HTML but places it in my normal inbox. Strange though I agree.

Cheers

Mark
Post Reply