Forum Moderators: coopster

Message Too Old, No Replies

Email not being received

         

dbarasuk

5:38 pm on Dec 15, 2007 (gmt 0)

10+ Year Member



Hello,

I have a script intended to send an email message to a user who has forgotten his/her login details using the email provided on a HTML form and registered in the database. The problem is that I don't receive the email sent by the system while I really get a confirmation message on the HTML page that the email was successfully sent by the server to the provided email by the user. How can I understand that?

Here's the code, maybe search for a possible bug for help:

<?php
include('../includes/connection.inc.php');
// check if the submit button has been clicked
if(array_key_exists('submit_1', $_POST)) {
$email_1 = strip_tags(trim($_POST['email_1']));
$status = false;
$msg = array();
if(stristr($email_1, '@') ¦¦ stristr($email_1, '.')) {
$status = true;
// In this cas the mail address is valid so build the query string
// first define the connection type
$darconn = dbconnect('Admin');
$sql = "SELECT username, pwd FROM friends WHERE email ='$email_1'";
$result =mysql_query($sql, $darconn) or die('Cannot connect to Mysql database');
if($result) {
$row = mysql_fetch_assoc($result);

}
If($row) {
// it's ok to extract the passwors and username of the user and email them to him
// assumed no other person will pretend to be the owner of that email
// prepare the email format
$usrname = $row['username'];
$pwd = $row['pwd'];
$to ='$email_1';
$subject ='Your request for login details';
$message ="This is in response to login details at site http://www.example.com.\n
Your username or
userId is\n\nt$$usrname\n\tYour Password is:$pwd";
$headers = "From: desk@example.com";
$mailsent = mail($to, $subject, $message, $headers);

if($mailsent) {
$msg[] = "An email has been sent to the provided email address, please check your email after some time.";

}
else {
$msg[] = "There was a system error trying to send you your login details, please try again.";
}
}

else {
$msg[] = "The email you provided is not registered with us, please use the email you registered with us.";
}

}
else {
$status = false;
$msg[] = 'Your email address is not correct';
}
}



?>

Any help to understand this, please?

Regards,
D.B

[edited by: coopster at 5:56 pm (utc) on Dec. 15, 2007]
[edit reason] exemplified details [/edit]

cameraman

8:03 pm on Dec 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here:
$to ='$email_1';

remove the single quotes so it's:
$to =$email_1;

The single quotes are causing the email to be sent literally to $email_1, not the contents of $email_1.

You also need to drop a dollar sign here:
userId is\n\nt$$usrname\n\tYour Password is:$pwd";

to:
userId is\n\nt$usrname\n\tYour Password is:$pwd";

dbarasuk

11:25 pm on Dec 15, 2007 (gmt 0)

10+ Year Member



Cameraman,
thank you so much:
The first mistake came from a misunderstanding of the meaning of single quotes while the second one was a typo error

Thank you again

D.B