A
Anonymous
Guest
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.
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.
Code:
<?php
/*
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");
include("incPHP1.inc");
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' => 'myemail@yahoo.com',
'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>");
}
else
{
echo("<p>Message successfully sent!</p>");
}
}
mysqli_close($cxn);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Test form to email</title>
</head>
<body>
</body>
</html>
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.