Jump to content

Recommended Posts

$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.

Link to comment
https://forums.phpfreaks.com/topic/301924-email-code-wont-send/
Share on other sites

// 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 by Jacques1

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.