如果满足所有条件并且回显“成功”,则以下脚本应该发送电子邮件。这里的问题是它返回“成功”但是没有发送电子邮件。我尽力弄清楚问题,但无法理解,因为我是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 = "auto_responder@geniusfree.net";
$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 :(得分:1)
检查MX输入设置。最高优先级为0.如果您在主机中使用邮件服务器。第一个条目应该是这个优先级数0 ---&gt; mail.yoursite.com。
另一种调试方法是使用电子邮件跟踪路由。你可以在cpanel中完成。
希望这有帮助。
答案 1 :(得分:0)
首先,您需要配置php以从您的服务器发送电子邮件,如果您在本地主机上运行代码,那么您必须配置您的php.ini文件以发送电子邮件,如果代码在Web托管服务器上运行,那么请联系他们为这个问题, 有关配置详细信息,请参阅send mail using xampp in php
如果您使用其他本地服务器(如wamp),则必须在服务器上单独(下载)安装sendmail实用程序。
希望这适合你
答案 2 :(得分:-1)
你在本地主机上运行它吗?如果是这样,它可能无法在那里工作,请在Web Host上测试它,让我知道结果。