Emails Don't Arrive

Do you have questions regarding Pecl or Pear? ask here!

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 7
Joined: Fri Mar 07, 2014 10:43 am

Sat Nov 08, 2014 7:35 pm

I've been having a world of problems trying to send e-mail using php code and smtp authentication with PEAR. My latest problem is that emails seem to be sent but never arrive. My login page has a "Forget Password" link that starts a javascript that randomly generates a 10-digit temporary password which is then passed to the following php file along with the login name.

Code: Select all

	file to send new randomly generated 10-digit temporary email to users when they have forgotten their original password

	ini_set("include_path",$_SERVER['DOCUMENT_ROOT'] ."\\included_files;".$_SERVER['DOCUMENT_ROOT'] ."\\referenced_files;"."C:\\Program Files (x86)\\Parallels\\Plesk\\Additional\\PleskPHP5\\PEAR;"."C:\\Program Files (x86)\\Parallels\\Plesk\\Additional\\PleskPHP5\\PEAR\Mail");

	require_once "Mail.php";

	$email = $_REQUEST[email];
	$newPW = $_REQUEST[newpw];

	echo "The new password for '".$email."' is '".$newPW."'\n\n<br><br>";

	$cxn=mysqli_connect($host,$user,$password,$database) or die ("Couldn't connect to the server.");
	if (mysqli_connect_errno())
		echo "Couldn't connect to MySQL: " . mysqli_connect_error();
	$result = mysqli_query($cxn, "SELECT * FROM userfile WHERE User_Email = '".$email."'") or die ("Couldn't open the IP lookup table.");
	$counter = mysqli_num_rows($result);
	if($counter == 1)
		while($row = mysqli_fetch_array($result)) 

			$fName = $row['First_Name'];
			$lName = $row['Last_Name'];
			$fullName = $fName." ".$lName;


		$to = $email;
		$subject = "Profile Update";
		$body = $fullName." has been issued '".$newPW."'as a temporary password.  Please login using this temporary password.  You will immediately be prompted to change your password.  Please do so.  Thank you for using the Safety, Health and Environmental Toolbox.\n\nSystem Administrator";

		echo "To = '".$to."'\n<br>Subject = '".$subject."'\n<br>Body = '".$body."'\n<br>";

		$headers = array (
			'From' => $mailuser,
			'Reply-To' => '',
			'To' => $to,
			'Subject' => $subject);
		$smtp = Mail::factory('smtp',
			array ('host' => $mailHost,
				'auth' => true,
				'username' => $mailUser,
				'password' => $mailPassword));

		$mail =& $smtp->send($to, $headers, $body);

		if (PEAR::isError($mail))
			echo("<p>" . $mail->getMessage() . "</p>");
			echo("<p>Message successfully sent!</p>");


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""> 
	<title>test form to email</title>

The php file then gathers additional information from the underlying SQL database to generate an email back to the user. A screenshot of what I get is attached. As you can see, the error handler generates a message saying the message was successfully sent. I've used this many times changing the $to value to use two (2) different email accounts on two different domains / servers. In every case, the program says that the message was successfully sent but no message ever reaches either account (or their spam folder). I'm using "localhost" for $mailHost, An active email address on my hostgator hosted site as my $mailUser" and the password associated with my email account for the $mailPassword. The technical support team at hostgator is being difficult about helping me with this problem so I'm hoping that someone on this forum can give me some insight.
20141106 emailPassword Screenshot.jpg
20141106 emailPassword Screenshot.jpg (107.26 KiB) Viewed 2255 times

New php-forum User
New php-forum User
Posts: 14
Joined: Wed Feb 25, 2015 7:38 am

Sun Mar 15, 2015 7:58 am

FYI, this happens a lot when on a shared server. Since SMTP servers are being shared with thousands of shared hosting users as well. Image

New php-forum User
New php-forum User
Posts: 72
Joined: Wed Jun 12, 2013 9:30 pm

Mon Apr 11, 2016 5:01 am

If some email is getting through, it is probably not a drupal or php problem. Check your mail server logs.

Post Reply