【问题标题】:Sending password link to email when user forget password用户忘记密码时将密码链接发送到电子邮件
【发布时间】:2013-06-24 12:45:42
【问题描述】:

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

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

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

【问题讨论】:

标签: php html email


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    您可以使用PHPMailer发送邮件

    这是PHPMailer的简单教程

    How to send mail using PHP

    【讨论】:

    • 如果你喜欢这个答案,那么你可以接受或投票给答案
    • 但是投票需要一些声望点...我没有...那些。我已经接受了塞尔吉奥的回答......
    猜你喜欢
    • 2016-08-31
    • 2018-08-17
    • 2011-02-19
    • 2015-06-22
    • 2013-06-13
    • 2013-03-04
    • 1970-01-01
    • 1970-01-01
    • 2012-02-29
    相关资源
    最近更新 更多