![](/img/trans.png)
[英]forget password page, creating a generated password to email to the user.
[英]Sending password link to email when user forget password
我有一個問題,當用戶單擊“忘記密碼”鏈接時,如何將密碼鏈接發送到用戶電子郵件。
這是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");
//如果您不提交表單,將直接顯示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>
任何建議都是可以接受的。
如果要發送電子郵件,請使用以下代碼:
$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);
請注意,如果您不驗證用戶輸入,則存在諸如標頭注入之類的安全問題。 良好的電子郵件驗證是這樣的:
$to = $_POST["email"];
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { /*mail is ok*/ }
else {/*mail is NOT ok*/}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.