I have the following code to retrieve the password of a user from the database and email to him. I am successfully able to send a user his password if his email is present in the database. But in the event that the email doesn’t exist, I want the code to echo that the email for the particular user doesn’t exist in the database. My code gives me the below result if an invalid email is entered in the form:
Failed to add recipient: @localhost [SMTP: Invalid response code received from server (code: 555, response: 5.5.2 Syntax error. v9sm2318990paz.6)]
I have tried using the if-else statement for this purpose. Here’s the code I wrote:
<?php
//Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");
// email value sent from HTML form
$email_to=$_POST['email'];
// table name
$tbl_name="registration";
if($mysql1 = "SELECT ID,Email,Password FROM $tbl_name WHERE Email='$email_to' ORDER BY ID DESC ")
{
$selectemail = mysql_query($mysql1);
$shah = mysql_fetch_array($selectemail);
$EMAIL = $shah['Email'];
$UID = $shah['ID'];
$password = $shah['Password'];
require_once "/home/computat/php/Mail.php";
$from = "abhishekagrawal.988@gmail.com";
$to = $EMAIL;
$subject = "Your password for www.computationalphotography.in";
$body = "Your password for logging on to our website www.computationalphotography.in is:\n$password\r\nIf you have any additional queries, kindly write to us at abhishekagrawal.988@gmail.com\r\n\nThanks & Regards\nThe Computational Photography Team\n";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "abhishekagrawal.988@gmail.com"; //
$password = "*********";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p></p>");
}
}
else{
echo "<b><center>Email not found in the database</center></b>";
}
/*
Use this
Avoid using
mysql_*functions usemysqli_*orPDOasmysql_*is being depreciated