I'm nearing my wits end on this...
I have a page setup to send an html email of a report that is generated by a given date. This form works great, exactly as expected. Now I am trying to create a new form to send a simple html email to someone and I'm being stymied at every turn...
Here's the code of the page that works (the addresses have been changed to protect the innocent):
PHP Code:
<?PHP
if(isset($_POST["email"])){$to=$_POST["email"];}
if(isset($_POST["body"])){$body=$_POST["body"];}
if(isset($_POST["date"])){$date=$_POST["date"];}
$body=strip_tags($body, '<table><tr><td><p><br><div>');
$subject = "Sales report for $date";
$random_hash = md5(date('r', time()));
$headers = "From: example@example.com\r\nReply-To: example@example.com\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
ob_start();
?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Your email does not support HTML formatted email.
--PHP-alt-<?PHP echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<html>
<body>
<?PHP echo $body;?>
</body>
</html>
--PHP-alt-<?PHP echo $random_hash; ?>--
<?PHP
$message = ob_get_clean();
mail( $to, $subject, $message, $headers );
echo "Message has been sent. Please use the back button on your browser to return to the report.";
?>
The $body is a table that is pulled from the report page. Now, I've replaced the <?PHP echo $body;?> line with something simple like <p>Hello world</p> and the email still sends fine. HOWEVER, when I try to create a new email page, I get nothing but the subject! Here's what I'm trying:
PHP Code:
<?PHP
$to="my@email.com";
$subject = "Test email";
$random_hash = md5(date('r', time()));
$headers = "From: example@example.com\r\nReply-To: example@example.com\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
ob_start();
?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Your email does not support HTML formatted email.
--PHP-alt-<?PHP echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<html>
<body>
<p>Hello, world!</p>
</body>
</html>
--PHP-alt-<?PHP echo $random_hash; ?>--
<?PHP
$message = ob_get_clean();
mail( $to, $subject, $message, $headers );
echo $message;
?>
For some reason, this doesn't work! I copied the code from the above page and the only changes I made was to remove references to $body and set the $to variable.
Please help. I'm about to drop-kick my web server...
One more ridiculous question... Is there somewhere you need to authorize a page to send email? I don't remember ever having to do that... Or would the name of the file have anything to do with it? Or the directory in which it's stored?
Bookmarks