Hi Can any One Help me in Sending e mail .
I am creating code for Forget password where iam sending the password to those eho forget based on their Email iD. It Partially works but Sends Error as

Cannot send password to your e-mail address ie error 3

and my code is

<?$email=mysql_real_escape_string($_POST['email_to']);

$sql="SELECT `user_pass` FROM tbl_user WHERE 
user_email='".$email."'";
$result=mysql_query($sql,$con);

$count=mysql_num_rows($result);
if (isset($_POST['Submit']))
{
if($email == "")
{
$error ="Enter Email";
}

elseif($count==1){

$row=mysql_fetch_array($result);
{

$password = $row['user_pass'];

}

$to=$email;

$subject="Your password here";

$header="from: B2Bassociates";

$messages= "Your password for login to our website \r\n";
$messages.="Your password is $password \r\n";
$messages.="more message... \r\n";

$sentmail = mail($to,$subject,$messages,$header);

}

else {
$error1 = " Not Found ";
}

if($sentmail){
$error2 = "Your Password Has Been Sent To Your Email Address.";
}
else {
$error3 = "Cannot send password to your e-mail address";
}
}
?>

Try replacing the last couple of lines with the following:

if($sentmail){
$error2 = "Your Password Has Been Sent To Your Email Address.";
}
else if (isset($sentmail)){
$error3 = "Cannot send password to your e-mail address";
}
}
?>

Glad to see code tags with syntax properties used on large chunks of code for once.:)

Hi,

Try to debug your code as why the email is not going...
As far as mail function is concerned, it return true if mail is sent and returns false if mail is not sent.

So just use

echo $sendmail

And see what value is coming and then use if function.

Hi Cwarn23,
No changes to ur solution.
Still throws the same error as Cannot send password to your e-mail address Thanks for ur reply.

Hi Varun,
As u told, i made the changes and echos the email but it didnt displays any thing. I Dont know where i went wrong .Can u help me Plz.


Thanks

If it isn't displaying anything chances are the true/false statement is not being stored. So perhaps the following might be better:

<?$email=mysql_real_escape_string($_POST['email_to']);

$sql="SELECT `user_pass` FROM tbl_user WHERE 
user_email='".$email."'";
$result=mysql_query($sql,$con);

$count=mysql_num_rows($result);
if (isset($_POST['Submit']))
{
if($email == "")
{
$error ="Enter Email";
}

elseif($count==1){

$row=mysql_fetch_array($result);
{

$password = $row['user_pass'];

}

$to=$email;

$subject="Your password here";

$header="from: B2Bassociates";

$messages= "Your password for login to our website \r\n";
$messages.="Your password is $password \r\n";
$messages.="more message... \r\n";

if(mail($to,$subject,$messages,$header)){
$error2 = "Your Password Has Been Sent To Your Email Address.";
}
else {
$error3 = "Cannot send password to your e-mail address";
}
}

else {
$error1 = " Not Found ";
}
}
?>
This article has been dead for over six months. Start a new discussion instead.