0

我有问题,当用户单击忘记密码链接时,如何向用户电子邮件发送密码链接....

这是 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>

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

4

2 回答 2

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*/}
于 2013-06-27T06:33:19.843 回答
1

您可以使用发送邮件PHPMailer

这是简单的教程PHPMailer

如何使用 PHP 发送邮件

于 2013-06-27T06:49:20.613 回答