I have a simple password send that will send them their password when they enter their email but the only problem is that I am getting an error when I load the page that says
Failed to add recipient: @localhost [SMTP: Invalid response code received from server (code: 501, response: <@localhost>: no local part)]
I know that the information is correct. Here is the code- (Yes I know not using mysqli is insecure. This is for a quick thing.)
<?php
$username = "sdfsdfsdf";
$password = "sdfsdfsdf";
$hostname = "dsfsdfsdf";
$dbconn = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$emailto = $_POST['email'];
$database = mysql_select_db("jjlliinn_test",$dbconn);
$query = "SELECT password FROM agentclient WHERE email = '$emailto'";
$result = mysql_query($query) or die(mysql_error());
$data = mysql_fetch_assoc($result);
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
require_once "Mail.php";
$from = "JLP <no-reply@sdfsdfsdfsdfsdfsdfsdf.net>";
$to = "$toemail";
$subject = "Your password";
$body = "Hi,
Your password is $data.";
$mailhost = "mail.sdfsdfsdfsdf.net";
$mailusername = "no-reply@sdfsdfsdfsdf.net";
$mailpassword = "Uq?sdfsdfsdfsdfsdf-";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $mailhost,
'auth' => true,
'username' => $mailusername,
'password' => $mailpassword));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Password successfully sent!</p>");
}
mysql_close($dbconn);
?>
You did not configure SMTP server on your local host you should look into here:
How to configure WAMP (localhost) to send email using Gmail? http://rajeshstutorials.blogspot.com/2012/04/how-to-set-up-smtp-server-on-localhost.html
should help.
Your code sends any email to localhost
, due to this typo:
$to = "$toemail"; # empty-string assignment! Should be "$emailto"