Reputation: 1613
I have the problem, how to send a password link to user email when the user clicks the forget password link....
Here is ForgetPasswordViewController.php... i developed this for simply showing a alert... But when coming to real time.. i don't know how to send the password link.. to user email...
<?php
header("Cache-Control: private, must-revalidate, max-age=0");
header("Pragma: no-cache");
header("Expires: Fri, 4 Jun 2010 12:00:00 GMT");
//If you are not submitting the form HTML will be directly shown
if (!isset($_POST['submit']))
{
?>
<html>
<body>
<form name='f1' method="POST" action="" onSubmit="return ValidateEmail();">
<div id="fp">
<span style="margin-left:-50px">Email:</span>
<span><input class="input" type="text" name="Email" placeholder="Enter mailID" required></span><br>
<input style="height:50px; width:120px; background:url(Images/submit_butto.gif) no-repeat right top; border: none;" type="submit" name="submit" value="">
<?PHP
}
else
{
$Email=$_POST['Email'];
if(!empty($Email))
{
$model = new UsersModel();
$rowsCount = $model->checkUserEmail($Email);
echo $rowsCount;
if ($rowsCount!=0)
{
//If you are submitting the form insert the details into database
echo '<script type="text/javascript">alert("A password hasbeen sent to your Email..");
window.location.href="LoginViewController.php";</script>';
}
else
{
echo'<script type="text/javascript">alert("Enter valid email");
window.location.href="ForgetPasswordViewController.php";</script>';
}
}
}
?>
</body>
</html>
Any suggestions are acceptable....
Upvotes: 0
Views: 2783
Reputation: 4557
You can send mail using PHPMailer
Here is the simple tutorial for PHPMailer
Upvotes: 1
Reputation: 28845
Use this code if you want to send an email:
$to = '[email protected]';
$subject = 'Subject here';
$message = "Content";
$message .= "more Content";
$message .= "even more Content or a variable".$variable;
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Be aware that there are security issues like header injection if you don't validate the user input. A good email validation is this:
$to = $_POST["email"];
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { /*mail is ok*/ }
else {/*mail is NOT ok*/}
Upvotes: 2