View Full Version : Sending HTML email from php. where am i going wrong?

01-09-2008, 02:25 PM
i'm trying to get php to send a html email from a page, here is my source code, what am i doing wrong?

$emailaddress = 'Test@Email.com';
$fullame = 'Full Name';
$to = $emailaddress;
$subject = "Aknowledgement";
$body = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html;" .
"charset=iso-8859-1\" /><style>" .
"body, p{font-family: Trebuchet MS, verdana;color: #666666;font-size:12px;}" .
"a, a:visited{font-family:Trebuchet MS, verdana;text-decoration: underline;color: #6C408D;font-size:12px;}" .
"a:hover{font-family:Trebuchet MS, verdana;text-decoration: none;color: #6C408D;font-size:12px;}" .
"</style></head><p>Dear " . $fullname . ",</p><p>Thank you for your request.</p>" .
"<p>We will contact you shortly.</p>" .
"<p>Regards</p><p><strong>Visit our website:</strong> <a href=\"#\" target=\"_blank\">#</a>";
$headers = "From: emailsender@Email.com\n" .
"X-Mailer: php\n" .
"Content-type: text/html; charset=iso-8859-1";
mail($emailaddress, $subject, $body, $headers);
echo("mail SENT to:"$emailaddress"!");

any help is greatly appreciated.

01-09-2008, 04:44 PM
Thanks to spammers, sending automated email with PHP is a little bit of a dark art.

I would strongly suggest using a pre-written mail class such as PHPMailer, Zend Mail or PEAR::mail (to name a few). These classes have proven code in them and allow you to send both plain text and HTML versions of your message.

Sending mail with PHP just isn't as simple as using the mail function (which doesn't actually send mail BTW) anymore.