bc123 Posted August 17, 2016 Share Posted August 17, 2016 $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $result = mysql_query("SELECT * FROM statistics"); while($row = mysql_fetch_array($result)) { $content_material="<tr><td>". $row['ip_address']."</td><td>".$row['number_of_pages_visited_for_whole_month']."</td><td>".$row['unique_visits']."</td></tr>".$content_material; } $content_material="<table width='600' border='1'><tbody><tr><td>Visitor</td><td>Visits on Separate Days</td><td>Total Number of Pages Visited</td></tr>".$content_material."</tbody></table>"; ////////////END TABLE ////////////BEGIN MAILING FEATURE $headers = "Content-type: text/html; charset=iso-8859-1"; $headers = $headers."From: \"My Self\" <webmaster_email>\r\nReply-to: webmaster_email"; $message ="Hi.<br><br>The visitor statistics for last month are as follows.<br><br>The total number of visitors last month are ".$total_visitors.". These vistors visited on ".$unique_visits." seperate days last month. The amount of pages these visitors visited over the last month is ".$number_of_pages_visited_for_whole_month.".<br><br>".$content_material."<br><br>Sincerely,<br>Automated name"; print_r($message); mail( "recipient@gmail.com", "Visitor Statistics for Last Month", $message, $headers, '-f webmaster_email'); Above is the code for my project. If I try and send $message with it containing $content_material, the email won't send. If I remove $content_material from $message then the email will be sent just fine. If I print_r($message), as is indicated in the code, the $message will display perfectly fine with $content_material displaying just fine as well. I can't figure out why it is doing this. Any help would be appreciated. Thank you. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 17, 2016 Share Posted August 17, 2016 (edited) // Moving to the right forum. This is not a math problem. Your mail headers look fudged up. There's no CR LF separator between the Content-Type header and the From header, so effectively none of them is valid. You also need to check the return value of mail() to give you an idea where the e-mail got stuck. Is it not even passed to your mail relay? Does Gmail reject it? But the real problem is that your code is ancient. I assume you've copied and pasted this from somewhere? Because this stuff is from the 90s; you shouldn't even know it when you've just started learning PHP. The mysql_* functions are obsolete since more than a decade and have already been removed from PHP. Nowadays, we use PDO. Nobody has to mess with the low-level mail() function anymore. Nowadys, we use PHPMailer (or an equivalent library). When you start writing code for the 21st century, a lot of your problems may actually go away. Edited August 17, 2016 by Jacques1 Quote Link to comment Share on other sites More sharing options...
bc123 Posted August 18, 2016 Author Share Posted August 18, 2016 I'm not exactly sure of what you are suggesting I do. what is the CR LF separator? Also, how to I check the return value of mail()? THank you. I'm also looking to simply resolve this - not go with learning a whole new program. Thanks again. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 18, 2016 Share Posted August 18, 2016 Maybe you could google "cr lf" or "cr/lf"? And then maybe you could look up the mail function in the official php online manual for an example of how it is used? It's not about learning "a whole new program" it is about learning aabout the "program" you are trying to use right now. The Official PHP manual function reference is: http://www.php.net/manual/en/funcref.php You are welcome. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.