I am trying to write a simple mail script that will email a users password to them when they request it. But this is on a windows IIS server, trying to connect to an exchange server to send the mail. I'm sure there has to be some kind of authentication. Can this be done in PHP?
My simple mail script looks like this:
if ($send == 'yes')
{
email_password($user_name);
if (email_password($user_name) == true)
{
echo " An email has been sent to your mailbox. Check your email in a few minutes to retrieve your password. <br/> \n";
}
else
{
echo " Failed to send notification. Please contact your administrator at webmaster@*. <br/>\n";
}
}
else
{
print("
<form name=\"forget_password\" method=\"post\" action=\"forget_password.php\">\n
--- Please enter your User Name ---<br/>
<input type=\"text\" name=\"user_name\" size=\"50\"><br/>\n
<input type=\"hidden\" name=\"send\" value=\"yes\"><br/>\n
\t<input type=\"submit\" name=\"subBTN\" value=\"Proceed\">\n
</form>\n
");
}
the email_password function looks like this:
function email_password ($user_name)
{
global $train_db;
global $web_root;
db_connect($train_db);
$query = "SELECT * FROM login WHERE user_name = '$user_name' ";
$results = @($query);
$pass = mysql_fetch_array($results);
$email = $pass[email];
$from = "From: webmaster@*. \r\n";
$mesg = "Your Training Database password is: $pass[password]";
if (mail($email, "Training Database Login Information", $mesg, $from))
{
return true;
}
else
{
return false;
}
}
I placed the IP address of the exchange server in php.ini under SMTP and my email address under sendmail_from. The account is a valid account on the exchange server.
I get an "unable to connect" error.
I've tried putting the server name instead of the ip address... same error.
thanks for any help in advance,
chadT