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);
?>
Trouble Importing & Sending HTML email
Moderator: General Moderators
-
Cruzado_Mainfrm
- Forum Contributor
- Posts: 346
- Joined: Sun Jun 15, 2003 11:22 pm
- Location: Miami, FL
What about the " characters in the include statement. Should they be backslashed out as \"http://etc...\"
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
Thanks
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.
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
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