Trouble Importing & Sending HTML email

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

Post Reply
davidrock
Forum Newbie
Posts: 3
Joined: Sat Oct 04, 2003 8:08 am

Trouble Importing & Sending HTML email

Post by davidrock »

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="David Rock<test@frii.com>";
$headers ="From: admin@frii.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$subject ="HTML Newsletter test";

// read the html contents into $body
ob_start();
include ("http://www.benefitssummary.com/nl/testfile.html");
$body = ob_get_contents();
ob_end_clean();

// $body = htmlspecialchars($body);
// $body = addslashes("$body");
// print ("$body");

mail($to, $subject, $body, $headers);
?>
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

have you set an SMTP server in the php.ini file?
if you haven't your mail is not going anywhere, if you use winxp you can use the SMTP server of IIS
mikeb
Forum Commoner
Posts: 60
Joined: Tue Jul 08, 2003 4:37 pm
Location: Dublin, Ireland

Post by mikeb »

What about the " characters in the include statement. Should they be backslashed out as \"http://etc...\"
davidrock
Forum Newbie
Posts: 3
Joined: Sat Oct 04, 2003 8:08 am

Post by davidrock »

Yes, I have confirmed that php.ini is configured with a valid SMTP server. In fact I'm able to send message through it from PHP, but it seems that PHP's mail() is encountering something it doesn't like in the imported HTML that I'm trying to send and fails without giving any error message. I need to find out what - if any, limitations exist on the range of characters mail() can deal with in the message body.

Thanks
davidrock
Forum Newbie
Posts: 3
Joined: Sat Oct 04, 2003 8:08 am

Post by davidrock »

I've determined the include statement is working properly because I can display the the expected HTML code after it's assigned to $body. Seems like I must be missing something basic here but I can't pinpoint it yet. The HTML code that I'm importing and trying to send renders perfectly when displayed in Internet Explorer and when sent from IE to M$ Outlook as an email message so I ddon't know why my method above isn't working.
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Post by evilMind »

First, which flavor of php are you using (and on which OS)? If you are using php < 4.3 on a Micro$uck computer then you should try upgrading since <4.3 had problems w/additional headers in the mail() function.
Also, I've found that at times \r\n can be problimatic (depending on which MTA you are using). You might try using either \r or \n but not both and see if that helps. It's a long shot but you never know ;)
Post Reply