【问题标题】:Forgot Password. Not getting an email in yahoo/gmail or other mail忘记密码。没有收到 yahoo/gmail 或其他邮件中的电子邮件
【发布时间】:2014-02-04 17:38:38
【问题描述】:

我创建了一个忘记密码。它检查电子邮件是否存在于数据库中,并创建一个激活码。但是,我没有从我输入的电子邮件中收到任何邮件。我必须安装一些东西才能使这项工作吗?如果您发现这是重复的,那不是因为发布此忘记密码的其他人正在为他们工作,但就我而言,我没有收到电子邮件。

代码如下:

<?php 
error_reporting(0);
if($_POST['submit']=='Send')
{
//keep it inside
$email=$_POST['email'];
$code = $_GET['activation_code'];
$con=mysqli_connect("localhost","root","","test");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$query = mysqli_query($con,"select * from users where user_email='$email'")
or die(mysqli_error($con)); 

 if (mysqli_num_rows ($query)==1) 
 {
$code=rand(100,999);
$message="You activation link is: http://192.168.0.108/resetpass.php?email=$email&code=$code";
mail($email, "daleii.calderon@yahoo.com", $message);    
echo 'Email sent';
$query2 = mysqli_query($con,"update users set activation_code='$code' where user_email='$email' ")
or die(mysqli_error($con)); 
}
else
{
echo 'No user exist with this email id';

}}

?>
<form action="forgot.php" method="post">
Enter you email ID: <input type="text" name="email">
<input type="submit" name="submit" value="Send">
</form>

【问题讨论】:

  • 您在使用共享主机吗? mail() 功能真的很慢,尤其是在免费托管上。试试 PEAR mail 之类的东西。 pear.php.net/package/Mail/redirected
  • 我只是在使用本地主机先生.. 为什么我不能收到电子邮件?如果我收到电子邮件,发件人是谁?对不起,我只是在一个教程上跟着这个,先生,我只是一个新手..
  • 通过使用外部变量构建 SQL 语句,您将面临 SQL 注入攻击。 此外,任何带有单引号的输入数据,例如“O 'Malley",会炸毁你的 SQL 查询。请了解如何使用参数化查询(最好使用 PDO 模块)来保护您的 Web 应用程序。我的网站bobby-tables.com/php 有一些示例可以帮助您入门,this question 有很多详细示例。

标签: php mysql email


【解决方案1】:

您不能在本地主机上发送电子邮件。如果您想测试您的代码,您需要在允许发送电子邮件的免费托管网站上对其进行测试。 你的mail() 函数有一些错误。更好:

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>

【讨论】:

    【解决方案2】:

    您是否安装了本地邮件服务器?有很多免费的。例如,XAMPP 包含 2 个好的(fake-sendmail 和 Mercury)。对于开发而言,通常将邮件存储在本地就足够了,尤其是在使用真实电子邮件地址时要确保不会惹恼人们。

    您可以在这个问题中找到更多信息:How to configure XAMPP to send mail from localhost?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-23
      • 2021-08-16
      • 2016-08-31
      • 2011-02-19
      • 1970-01-01
      • 2018-08-17
      • 2021-10-30
      • 2013-06-13
      相关资源
      最近更新 更多