Reputation: 1
The query wise is working fine, i can echo out the email address and the password associated to the username however when it states that the email is being sent out i still do not receive it in my mailbox. Any idea what went wrong?
Here's my full code:
<?php session_start();
mysql_connect("localhost","root","");//database connection
mysql_select_db("database");
if (isset($_POST['username'])){
$username = $_POST['username'];
$query="select * from dbusers where username='$username'";
$result = mysql_query($query);
$count=mysql_num_rows($result);
// If the count is equal to one, we will send message other wise display an error message.
if($count==1)
{
$rows=mysql_fetch_array($result);
$pass = $rows['password'];//FETCHING PASS
echo "your pass is ::".($pass)."";
$to = $rows['email'];
echo "your email is ::".$to;
//Details for sending E-mail
$from = "Your Password details";
$url = "http://localhost.com";
$body = "Reset Password
-----------------------------------------------
Url : $url;
email Details is : $to;
Here is your password : $pass;
Sincerely,
Coding Cyber";
$from = "[email protected]";
$subject = "Here's your new password";
$headers1 = "From: $from\n";
$sentmail = mail ( $to, $subject, $body, $headers1 );
} else {
if ($_POST ['username'] != "") {
echo "No such username found!</span>";
}
}
//If the message is sent successfully, display sucess message otherwise display an error message.
if($sentmail==1)
{
echo "<span style='color: #ff0000;'> Your Password Has Been Sent To Your Email Address.</span>";
}
else
{
if($_POST['username']!="")
echo "<span style='color: #ff0000;'> Cannot send password to your e-mail address.Problem with sending mail...</span>";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Home: Webpage</title>
</head>
<body>
<form action="" method="post">
<label> Enter your User ID : </label>
<input id="username" type="text" name="username" />
<input id="button" type="submit" name="button" value="Submit" />
</form>
</body>
</html>
Upvotes: 0
Views: 333
Reputation: 6379
When you use xampp: Activate your Mercury Mail Transport in your xampp-control. Otherwise, your local mailserver is not started and you cant send Mails.
<?php
$a = '[email protected]';
$b = '';
$msg = 'Hello';
$header = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($a, $b, $msg, $header);
?>
Upvotes: 1
Reputation: 1025
If you are running your code in your localhost then that will never work for you.It's better if you want to send mail from your local server then use SMTP rather than simple mail functionality by PHP.
Upvotes: 0
Reputation: 33
If your files are in your localhost folder you need to install a local mail server, not pretty usefull, but it works.
And if yout website in online ( at a hoster ) it should works automatically, or go to the cpanel and activate the mailing.
Upvotes: 0