I am trying to send email which contains password of the user. i want to retrieve email id from database. and my password field and email field are in different tables.
I have tried but mail is not going to the email id.
Here is the code:
HTML:
UserName: <input type="text" name="txt_usrnm"/>
Security Ques:<select name="sec_ques_drpdwn">
<option>What is your academy's first number?</option>
<option>what is your nick name?</option>
<option>What is your favourite colour?</option>
<option>What is your pet name?</option>
</select>
Security Ans:<input type="text" name="txt_sec_ans"/>
<input type="submit" name="submit" value="Submit" align="middle" style="width:auto" />
PHP code:
<?php
if(isset($_POST['submit']))
{
$usrnm=$_POST['txt_usrnm'];
$sec_ques=$_POST['sec_ques_drpdwn'];
$sec_ans=$_POST['txt_sec_ans'];
$user_name = "root";
$password = "";
$database = "show_your_talent";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found)
{
//print "Database Found ";
$substr=substr($usrnm,0,2);
if($substr=="AC")
{
$res="SELECT * FROM reg_ac WHERE UserName='".$usrnm."' and SecurityQues ='".$sec_ques."' and SecurityAns='".$sec_ans."'";
$res2="select Password from username where UserName='".$usrnm."'";
}
else
{
$res="SELECT * FROM reg_indi WHERE UserName='".$usrnm."' and SecurityQues ='".$sec_ques."' and SecurityAns='".$sec_ans."'";
$res2="select Password from username where UserName='".$usrnm."'";
}
$result = mysql_query($res);
$result2 = mysql_query($res2);
$count=mysql_num_rows($result);
if($count==1)
{
echo "count";
while ($row = mysql_fetch_array($result) && $row2 = mysql_fetch_array($result2))
{
echo "while";
$from = "Name <hmparikh15@gmail.com>";
$header = "From: ".$from;
//$header = "Reply-To: ".$from."rn";
$to = $row['E-mail'];
$subject = "Password Recovery ";
$emailBody = "UserName ".$row['UserName']."
Password ".$row2['Password']." \n";
echo $emailBody;
echo $to;
}
if (mail($to, $subject, $emailBody, $header))
{
echo "if mail";
echo "<script type='text/javascript'> alert('Password has been sent to your email id.')</script>";
}
else
{
echo "Email not sent. Please, try again after some time.";
}
}
else
{
echo "<script type='text/javascript'> alert('Wrong Question/Answer')</script>";
}
mysql_close($db_handle);
}
}
?>
Its printing the message : Password has been sent to your email id.
But its not sending the email.
Please help me.