当用户忘记密码时,发送密码链接到电子邮件

时间:2013-06-27 06:27:55

标签: php html 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");

//如果您没有提交表单,将直接显示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>&nbsp;&nbsp;
        <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>

任何建议都是可以接受的......

2 个答案:

答案 0 :(得分:2)

如果您想发送电子邮件,请使用此代码:

$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*/}

答案 1 :(得分:1)

您可以使用PHPMailer

发送邮件

以下是PHPMailer

的简单教程

How to send mail using PHP