PHP 7.0 STRPOS 未按预期运行

PHP 7.0 STRPOS not functioning as expected

所以,我试图使用 strpos 来测试变量中是否存在字符串,但是在我尝试使 if 语句起作用的所有尝试中,它都没有成功,所以我着手输出字符串并试图找到 strpos 检测到它的点,但它并没有明显存在!在这种情况下,我正在搜索 Gmail SMTP 错误代码的 SMTP 错误输出。
我知道如何修复错误,但我希望我的系统能够解析 smtp 错误并报告它们给我的用户...

PHP代码:

$Request = RequestPasswordReset($_POST["email"]);
echo $Request;
echo "<br>Position of Error Code: " . strpos($Request, "gsmtp SMTP code: 550");
die();
if($Request === "SUCCESS") {
    DisplayError("Password Reset Successful", "We have sent a email that contains a link to reset your password.", "/account/resetpassword.php");
} else if($Request === "USER_NOT_FOUND") {
    DisplayError("Password Reset Request Failed", "The specified email is not tied to any accounts in our system.", "/account/resetpassword.php");
} else if(strpos($Request, "gsmtp SMTP code: 550") !== false) {
    DisplayError("Password Reset Request Failed", "The mail was blocked by our relay due to IPs being not whitelisted.", "/account/resetpassword.php");
} else {
    DisplayError("Password Reset Request Failed", "The request failed for an unknown reason.", "/account/resetpassword.php");
}

文本输出:
它确实重复了自己,我重复了两次 $Request 并且它完全执行了以下两次

The following From address failed: XXXXXXX : MAIL FROM command failed,Invalid credentials for relay [XXXXXXX]. The IP address you've registered in your G Suite SMTP Relay service doesn't match domain of the account this email is being sent from. If you are trying to relay mail from a domain that isn't registered under your G Suite account or has empty envelope-from, you must configure your mail server either to use SMTP AUTH to identify the sending domain or to present one of your domain names in the HELO or EHLO command. For more information, please visit https://support.google.com/a/answer/6140680#invalidcred r126sm1314271qke.4 - gsmtp ,550,5.7.1SMTP server error: MAIL FROM command failed Detail: Invalid credentials for relay [XXXXXXX]. The IP address you've registered in your G Suite SMTP Relay service doesn't match domain of the account this email is being sent from. If you are trying to relay mail from a domain that isn't registered under your G Suite account or has empty envelope-from, you must configure your mail server either to use SMTP AUTH to identify the sending domain or to present one of your domain names in the HELO or EHLO command. For more information, please visit https://support.google.com/a/answer/6140680#invalidcred r126sm1314271qke.4 - gsmtp SMTP code: 550 Additional SMTP info: 5.7.1
Position of Error Code:

(编辑)重置密码请求函数:

function RequestPasswordReset($Email) {
// Try to Get User
$User = GetUser_Email($Email);

// Does user exist?
if($User === "NOT_FOUND") {
  return "USER_NOT_FOUND";
}

// Generate Link To Send with Email
$Link = GeneratePasswordResetLink();
$SendEmail = SendPasswordReset($User["Email"], $User["FirstName"] . $User["LastName"], $Link);

if($SendEmail !== "SUCCESS") {
  return $SendEmail;
} else {
  // WHAT IF MYSQL FAILS????? ~~~~~~~~~~~~~~~ NEED  SOLOUTION
  $PDO_Connection = CreateMySQLConnection();
  $PDO_CMD = $PDO_Connection -> prepare("UPDATE accounts SET ResetPassword=? WHERE Email=?");
    $PDO_CMD -> execute(array($Link, $User["Email"]));
  return "SUCCESS";
}
}


(编辑)发送密码重置功能:

$User = GetUser_ResetID($resetID);

$mail = CreateSMTPConnection();
$mail->AddAddress($targetAddress, $targetName);       // Add a recipient

$mail->IsHTML(true);                                  // Set email format to HTML
$mail->Subject = 'LitenUp Password Reset';
$mail->Body    = str_replace("https://mylitenup.net/account/resetpassword.php?ID=", ("https://mylitenup.net/account/resetpassword.php?ID=" . $resetID), file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/php/mailer/documents/resetpassword.html"));
$mail->AltBody = 'Reset Your Password: https://mylitenup.net/account/resetpassword.php?ID=' . $resetID;
$mail->XMailer = 'LitenUp Mailer';
$mail->XPriority = '1';

  try{
    $mail->send();
    return "SUCCESS";
  } catch (phpmailerException $e) {
    return $e->errorMessage();
  } catch (\Exception $e) {
    return $e->getMessage();
  }

(编辑):我试过 mb_strpos,但它不起作用,所以如果那是可行的,为什么它对我不起作用?我做了 mb_strpos($Request, "gsmtp SMTP code: 550");,但在执行后它回显了请求,但是 Position of Error Code: 行没有得到回显。

(更新 1):对于延迟,我深表歉意,在最坏的情况下,我会再次延长它的赏金。但是,你们是对的!当我第一次遇到错误时,我将它输出并复制了 "gsmtp SMTP code: 550" 行,但是在完成标记之后似乎出现了某种新行。您可以在 中看到该行应该更像 "gsmtp" + + "SMTP code: 550",但我不确定换行符应该是什么。我试过
和 \n.

我的最佳猜测:

您正在输出到 HTML,因此您的 CRLFs/LFs 可能呈现为 space。我会用 <pre>...</pre> 标签附上你的 echo 语句,看看是否是这样。 strpos 会失败,因为您正在搜索 space 字符,而它实际上是 CRLF/LF.

最好的解决办法是花时间准确地找出那个白色的字符是什么-space。

在你这样做之前,你可以只使用正则表达式掩盖其中的任何内容。

变化:

} else if(strpos($Request, "gsmtp SMTP code: 550") !== false) {

至:

} elseif(preg_match("/gsmtp\s+SMTP\s+code:\s+550/",$Request)) {