Link to home
Start Free TrialLog in
Avatar of Brad Bansner
Brad Bansner

asked on

PHP mail script not sending in HTML format

I have a PHP script that receives some incoming POST data to build a message. The message is sending, but not in HTML format. I receive the HTML code as text in the message, rather than an HTML-encoded mail message. I got most of this code from php.net, is there something I'm not doing quite right?

<?php

	$recipient=$_POST['recipient'];
	$subject=$_POST['subject'];
	$msg='<html><head><title>Liever, Hyman & Potter</head></html><body>' . $_POST['msg'] . '</body></html>';
	$headers='MIME-Version: 1.0' . '\r\n' . 'Content-type: text/html; charset=iso-8859-1' . '\r\n' . 'From:' . $_POST['sender'];

	mail($recipient, $subject, $msg, $sender);
	echo 'Mail Sent.';

?>

Open in new window


Thank you!
ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Brad Bansner
Brad Bansner

ASKER

Thanks for your help. Yes, the quotes were part of the problem. I also put $sender in the mail command when I should have put $header. AND I was missing the closing </title> tag. Sorry, that was really sloppy... I normally program in ASP so PHP isn't my thing. Thank you!
First, you not sending the 'headers'.  On http://us3.php.net/manual/en/function.mail.php , it shows the proper format to be:  mail($to, $subject, $message, $headers);

Second, your message format is not correct or complete for 'proper' HTML Multipart email.

@marqusG's suggestion to use PHPMailer is a good idea though the current page for it is http://code.google.com/a/apache-extras.org/p/phpmailer/downloads/list