[英]Sending password link to email when user forget password
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... 这是ForgetPasswordViewController.php ...我开发此程序只是为了显示警报...但是当进入实时时..我不知道如何将密码链接发送到用户电子邮件...
<?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 //如果您不提交表单,将直接显示HTML
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.... 任何建议都是可以接受的。
Use this code if you want to send an email: 如果要发送电子邮件,请使用以下代码:
$to = 'recepient@somemail.com';
$subject = 'Subject here';
$message = "Content";
$message .= "more Content";
$message .= "even more Content or a variable".$variable;
$headers = 'From: sender@yourdomain.com' . "\r\n" .
'Reply-To: sender@yourdomain.com' . "\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*/}
You can send mail using PHPMailer
您可以使用
PHPMailer
发送邮件
Here is the simple tutorial for PHPMailer
这是
PHPMailer
的简单教程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.