Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble Importing & Sending HTML email

Status
Not open for further replies.

DavidRock

Programmer
Joined
Jul 24, 2002
Messages
61
Location
US
I'm trying to import the contents of an HTML newsletter into a PHP script and mail it out, but it's not working correctly. I know the html file is importing correctly because I can see it when I display the contents of $body (see below). However, when I pass $body to PHP's mail() I don't recieve the message. If I use htmlspecialchars() on $body before mailing I recieve the message with the proper (unrendered) html code. And if I use addslashes() I recieve a message with the tables and text but hardly any proper formatting. PHP's mail() seems to be choking on some special characters. etc. in the html file but I can't figure out how to deal with it. The code I'm testing with is below. Can anyone help?

Thanks


<?
$to=&quot;David Rock<test@frii.com>&quot;;
$headers =&quot;From: admin@frii.com\r\n&quot;;
$headers .= &quot;MIME-Version: 1.0\r\n&quot;;
$headers .= &quot;Content-type: text/html; charset=iso-8859-1\r\n&quot;;
$subject =&quot;HTML Newsletter test&quot;;

// read the html contents into $body
ob_start();
include (&quot;$body = ob_get_contents();
ob_end_clean();

// $body = htmlspecialchars($body);
// $body = addslashes(&quot;$body&quot;);
// print (&quot;$body&quot;);

mail($to, $subject, $body, $headers);
?>
 
Sending HTML email is more complicated than just putting the HTML into a message body. There's a bunch of SMTP header manipulation that needs to take place, too.

I strongly recommend that you use PHPMailer. It's a PHP class for sending complex email messages and it's available here:
Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top