好的,我猜这很简单,或者我正在使用一些我不知道的东西。
我将从代码中删除多余的位,但已删除所有内容已经过测试。
原始代码基于我到处看到的非常常见的教程脚本。它正在上线:
while ($row = $res->fetch_array()) {
并且php失败了:在非对象上调用成员函数fetch_array()。
通常这会告诉我我的SQL失败或返回不需要的东西,我会有一个小修复,然后继续我的生活。然而,情况似乎并非如此。我一遍又一遍地使用SQL,它正在回归我想要的东西。
我认为它可能与在else中调用while循环(但这不应该是一个问题)或者邮件调用在while循环中有关。
原始代码:
$email = $link->real_escape_string($_POST["web_forgot_email"]);
$sendemail = 0;
$sql = "SQL to return Name and Email (Tested extensively and works)";
$res = $link->query($sql);
if ($res->num_rows == 0) {
$arr = array("web_forgot_success" => "web no account");
echo json_encode($arr);
} else {
while ($row = $res->fetch_array()) {
$sendemail = $row['CLIENT_EMAIL'];
$name = $row['NAME'];
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;
$mail->Username = "quizzically@quizzically.co.uk";
$mail->Password = "quizzically01";
$mail->From = "quizzically@quizzically.co.uk";
$mail->FromName = "quizzically";
$mail->AddAddress($sendemail);
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "quizzically password reset confirmation";
$mailer = "Email Message";
$mail->Body = $mailer;
if(!$mail->Send()) {
$arr = array("web_forgot_success" => "web no send");
echo json_encode($arr);
} else {
$arr = array("web_forgot_success" => "web forgot success");
echo json_encode($arr);
}
}
}
所以我重新调整了代码,以便首先找到变量$ sendemail和$ name,然后每次发送一封电子邮件(即使$ sendemail变量不为0),它会跳过if语句并返回else。我已经通过在else变量中将它发送给自己来测试$ sendemail变量,它绝对不是0.
好的是PHP不会失败,坏的是导致代码跳过整个if部分处理发送电子邮件的事情。
重新调整代码:
$email = $link->real_escape_string($_POST["web_forgot_email"]);
$sendemail = 0;
$sql = "SQL to return Name and Email (Tested extensively and works)";
$res = $link->query($sql);
if ($res->num_rows == 0) {
$arr = array("web_forgot_success" => "web no account");
echo json_encode($arr);
}
while ($row = $res->fetch_array()) {
$sendemail = $row['CLIENT_EMAIL'];
$name = $row['NAME'];
}
if ($sendemail != 0) {
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;
$mail->Username = "quizzically@quizzically.co.uk";
$mail->Password = "quizzically01";
$mail->From = "quizzically@quizzically.co.uk";
$mail->FromName = "quizzically";
$mail->AddAddress($sendemail);
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "quizzically password reset confirmation";
$mailer = "Email Message";
$mail->Body = $mailer;
if(!$mail->Send()) {
$arr = array("web_forgot_success" => "web no send");
echo json_encode($arr);
} else {
$arr = array("web_forgot_success" => "web forgot success");
echo json_encode($arr);
}
} else {
$arr = array("web_forgot_success" => "web forgot failed");
echo json_encode($arr);
}
我希望我做的事情已被弃用,我没有找到或没有什么,但任何帮助都会受到赞赏。
答案 0 :(得分:0)
答案是我自己无法完全测试。我在发送的电子邮件的消息中遇到了问题。这一定是抛出错误然后PHP在while循环中失败了。
HTML修复错误(这是一个未转义的双引号),一切正常,没有错误。