2013-04-17 39 views
0

如果满足所有条件并回显“成功”,那么以下脚本应该发送电子邮件。这里的问题是它返回“成功”,但电子邮件没有被发送。我尽力找出问题所在,但无法弄清楚,因为我是PHP新手。所以我正在寻找任何可能的帮助。任何帮助将不胜感激。预先感谢您PHP消息发送脚本不起作用

$sql = "SELECT id, username FROM user WHERE email='$e' AND activated='1' LIMIT 1"; 
    $query = mysqli_query($db_conx, $sql); 
    $numrows = mysqli_num_rows($query); 
    if($numrows > 0){ 
     while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ 
      $id = $row["id"]; 
      $u = $row["username"]; 

     $emailcut = substr($e, 0, 4); 
     $randNum = rand(10000,99999); 
     $tempPass = "$emailcut$randNum"; 
     $hashTempPass = md5($tempPass); 
     $sql = "UPDATE useroptions SET temp_pass='$hashTempPass' WHERE username='$u' LIMIT 1"; 
     $query = mysqli_query($db_conx, $sql); 
     $to = "$e"; 
     $from = "[email protected]"; 
     $headers ="From: $from\n"; 
     $headers .= "MIME-Version: 1.0\n"; 
     $headers .= "Content-type: text/html; charset=iso-8859-1 \n"; 
     $subject ="GeniusFree Password Reset"; 
     $msg = '<h2>Hello '.$u.'</h2><p>This is an automated message from GeniusFree. If you did not recently initiate the Forgot Password process, please disregard this email.</p><p>You indicated that you forgot your login password. We can generate a temporary password for you to log in with, then once logged in you can change your password to anything you like.</p><br /><p><a href="http://www.geniusfree.net/passwordreset.php?u='.$u.'&p='.$hashTempPass.'">Click here now to apply the temporary password shown below to your account</a></p><p>If you do not click the link in this email, no changes will be made to your account. In order to set your login password to the temporary password you must click the link above.</p>'; 
     if(mail($to,$subject,$msg,$headers)) { 
      echo "success"; 
      exit(); 
     } else { 
      echo "email_send_failed"; 
      exit(); 
     }} 
+0

我可能需要调试的步骤。首先,回显你发送给邮件功能的所有变量。他们看起来正确吗?也许你正在发送一个不同于你想象的电子邮件地址。第二:你运行的服务器是否允许php Mail?一些服务器对您可以使用和不能使用的内容有限制。 – jeremysawesome

+0

检查垃圾邮件。可能你的邮件会在那里。 –

+1

如果电子邮件是发送的,则mail()函数返回true,但它不能告诉你它是否成功发送。 –

回答

1

检查MX条目设置。最高优先级为0.如果您在主机中使用邮件服务器。第一项应该是这样的优先级号码0 ---> mail.yoursite.com。

另一种调试方法是使用电子邮件跟踪路由。你可以在cpanel中做到这一点。

希望这会有所帮助。

-1

您是否在本地主机上运行它?如果是这样,它可能不会在那里工作,请在Web主机上测试它并让我知道结果。

+0

这必须是评论,而不是答案。 – sectus

+0

@sectus他没有必要的代表评论。 – asprin

+0

在Web主机以及本地服务器上测试... –

0

首先,您需要配置php以从您的服务器发送电子邮件,如果您在本地主机上运行代码,那么您必须配置您的php.ini文件以发送电子邮件,并且如果代码在虚拟主机服务器上运行,与他们联系,针对此问题, 详细的配置信息可以参考send mail using xampp in php

,如果你使用的是像WAMP另一个本地服务器,那么你有你的服务器上单独(下载)安装sendmail的效用。

希望这适用于你