error message Notice: Undefined variable: sentmail in /home/stud/1/0472547/public_html/send_password.php on line 59

The code works but when wrong email is entered and it cant find it in the database it comes up with that error its all right but for some reason its saying undefined variable


// ---------------- SEND MAIL FORM ----------------

// send e-mail to ...
$to=$email_to;

// Your subject
$subject="Your password here";

// From
$header="from: your name <your email>";

// Your message
$messages= "Your password for login to Fast Learner \r\n";
$messages.="Your password is $your_password \r\n";
$messages.="more message... \r\n";

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

}

// else if $count not equal 1
else {
echo "Not found your email in our database";
}

//=============error message is here cant figure it out where it says if ($sentmail){
// if your email succesfully sent
if($sentmail){
echo "Your Password Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send password to your e-mail address";
}

?>

Recommended Answers

All 5 Replies

Somewhere up the top put:

$sentmail = NULL;

Matti Ressler
Suomedia

Somewhere up the top put:

$sentmail = NULL;

Matti Ressler
Suomedia

didnt work made more errors

It did not make more errors at all (not possible), in fact its not need. I just ran what you posted (with a minor addition to make it complete) and received an email as expected.

The problem is elsewhere in your code. The actual error message would help.


Matti Ressler
Suomedia

Hello cant see what u mean it sends email when the email is found from the database but it when there isnt a password that matches it comes up with the right message but says undefined variable

Not found your email in our database
Notice: Undefined variable: sentmail in /home/stud/1/242422/public_html/send_password.php on line 100
Cannot send password to your e-mail address

Well, as I first suggested, declare the variable:

$sentmail = NULL;

Matti Ressler
Suomedia

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.