tags:

views:

520

answers:

2
+2  A: 

Basically repeating what I answered for another question, I'm all for rolling-your-own in most situations, but when it comes to mail I'd heartily recommend making it easier on yourself and using something like Swift Mailer or PHPMailer (in that order, for my money).

As a side-bonus (and assuming you specify reply-to, etc), you also have much less chance of being tagged as spam.

EDIT: Maybe it's just the example you've used, but there's no actual HTML in your message. Why not just use plain text? And yes, I'd use one of the classes I suggest for plain text too.

da5id
The example I used doesnt use html in it but in reality I do have html in there.
Josh Curren
Suspected as much, but was just making the point - not so much for you even, more 'cos increasingly people seem to default to html email when often there's no need.
da5id
+1  A: 

Personally, I'm a fan of Pear Mail (http://pear.php.net/package/Mail) and Pear Mail_Mime (http://pear.php.net/package/Mail_Mime).

Sending an HTML e-mail (with a plain-text body, for clients that don't support HTML) is as simple as this:

include_once('Mail.php');
include_once('Mail/Mime.php');

$htmlBody = '<html><body><b>Hello World</b></body></html>';
$plainBody = 'Your client doesn\'t support HTML';
$em = Mail::factory('sendmail');
$headers = array('From'=>'[email protected]', 'To'=>'[email protected]', 'Subject'=>'Cool Email');
$mime = new Mail_Mime();
$mime->setTxtBody($plainBody);
$mime->setHtmlBody($htmlBody);
$message = $mime->get();
$headers = $mime->headers($headers);
$mail = $em->send('[email protected]', $headers, $message);
drowe