【问题标题】:PHPMailer to send email address verification email not working when REMOTEPHPMailer 发送电子邮件地址验证电子邮件在远程时不起作用
【发布时间】:2015-06-25 12:27:45
【问题描述】:

我正在尝试使用 PHPMailer 发送验证电子邮件并完成对我网站的新用户请求。当我在本地进行测试时,一切正常,并且我从我的 Outlook.com 电子邮件帐户收到了预期的电子邮件。但是,一旦我上传到我的虚拟主机服务器,它就不起作用。由于我使用的是 Outlook.com 电子邮件,因此我看不到需要更改的地方。我联系了我的主机支持,他们没有任何线索。无论如何,这是我的网络主机的回复:

SERVER -> CLIENT: 220-a2ss15.a2hosting.com ESMTP Exim 4.84 #2 Sat, 18 Apr 2015 11:31:25 -0400 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
CLIENT -> SERVER: EHLO williamsrn.com
SERVER -> CLIENT: 250-a2ss15.a2hosting.com Hello a2ss15.a2hosting.com [75.98.175.95]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 TLS go ahead
CLIENT -> SERVER: EHLO williamsrn.com
SERVER -> CLIENT: 250-a2ss15.a2hosting.com Hello a2ss15.a2hosting.com [75.98.175.95]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250 HELP
CLIENT -> SERVER: AUTH LOGIN
SERVER -> CLIENT: 334 VXNlcm5hbWU6
CLIENT -> SERVER: bWljcm90ZWNjb25zdWx0aW5nQG91dGxvb2suY29t
SERVER -> CLIENT: 334 UGFzc3dvcmQ6
CLIENT -> SERVER: d29ud29uKiEx
SERVER -> CLIENT: 535 Incorrect authentication data
SMTP ERROR: Password command failed: 535 Incorrect authentication data
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 a2ss15.a2hosting.com closing connection
SMTP connect() failed.
Mailer Error: SMTP connect() failed.

这是我处理新用户表单请求并使用 PHPMailer 发送电子邮件的 php:

<?php
/* REMOTE ONLY */
set_include_path(".:/usr/lib/php:/usr/local/lib/php:/home/william5/php/includes");

include 'db_connect.php';
require 'PHPMailer-master/PHPMailerAutoload.php';

$fname = $conn->escape_string($_POST['fName']);
$lname = $conn->escape_string($_POST['lName']);
$coname = $conn->escape_string($_POST['coName']);
$email = $conn->escape_string($_POST['inputEmail']);
$hash = md5( rand(0,1000) ); 
$pass = $conn->escape_string(md5($_POST['inputPassword']));
$fullName = $fname . $lname;

$sql = "INSERT INTO users (first_name, last_name, corp_name, email, password, hash) "
    . "VALUES ('$fname', '$lname', '$coname', '$email', '$pass', '$hash')";

if ($conn->query($sql) === TRUE) {
//echo "New record created successfully!<br>";


    $addy = "verifyEmail.php?qa=$email&qh=$hash";

    $message = "Hello $fname! <br>"
        . "Please click the link below to confirm your email and complete the registration process.<br>"
        . "You will be automatically redirected to a welcome page where you can then sign in.<br><br>"            
        . "Please click below to activate your account:<br>"
        . "<a href='$addy'>Click Here!</a>";

    $mail = new PHPMailer;

    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->Debugoutput = 'html';

    $mail->isSMTP();                                        // Set mailer to use SMTP
    $mail->Host = 'smtp-mail.outlook.com';                  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                                 // Enable SMTP authentication
    $mail->Username = 'xbox2112@outlook.com';               // SMTP username
    $mail->Password = '********';                          // SMTP password I removed this for my privacy
    $mail->SMTPSecure = 'tls';                              // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                      // TCP port to connect to
    $mail->From = 'xbox2112@outlook.com';
    $mail->FromName = 'GOD';
    $mail->addAddress($email, $fullName);                   // Add a recipient
    $mail->addReplyTo('xbox2112@outlook.com', 'Information');
    $mail->isHTML(true);                                   // Set email format to HTML
    $mail->Subject = 'Account registration confirmation';
    $mail->Body    = $message;                              //HTML Message  (if true)
    $mail->AltBody = 'alt body message';
try {
    $success = $mail->send();

    if($success) {
        echo "A confirmation email has been sent to $email with a link to activate your account. <br><br>Please check your email and select the link to complete your registration.";        
    }else{
        echo "Mailer Error: " . $mail->ErrorInfo;
    }

} catch (Exception $ex) {    
    echo $ex;      
}

} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

我不明白的是,就 SMTP 从我的本地服务器到远程服务器而言,并没有真正改变(也不应该),但是当我远程运行代码时它不起作用。我在 PHPMailer 包的顶部添加了 include_path,但我知道这是有效的,因为我在下面需要它。我还需要在 db_connect.php 中更改我的数据库设置,但我知道这也有效,因为它创建了数据库记录。任何帮助将不胜感激。谢谢,约翰

【问题讨论】:

  • 顺便说一句,密码字段实际上是我的密码,而不是******。我把它放在那里是为了我自己的隐私。谢谢。

标签: php email outlook smtp phpmailer


【解决方案1】:

您的 ISP 正在将您重定向到他们自己的邮件服务器。

在您的脚本中,您指定要连接到smtp-mail.outlook.com,但您正在连接到a2ss15.a2hosting.com,我怀疑这与Outlook.com 无关,而是与a2hosting 作为您的ISP 有关。阅读您的主机提供的任何文档,并与他们一起打开支持票以禁用此重定向。

the PHPMailer troubleshooting guide 中提到了这一点。

这也正是您应该启用加密和验证证书的原因(PHP 5.6 中的默认设置,但不是在此之前),因为他们所做的是中间人攻击,并且有效地揭示了您的这个未知的(幸运的是在这种情况下不是太未知)第三方的密码。

【讨论】:

  • +!你得到了我的第一个 +1!很好谢谢。更改为 a2ss15.a2hosting.com 后,一切正常。我将研究加密和验证证书。
  • 很高兴它成功了。不要忘记将其选为您的首选答案 - 点击 +1 按钮旁边的勾号!
【解决方案2】:

由于我没有足够的评论点,我会在这里告诉你。问题可能出在您的身份验证上,因为您可以正常连接到 SMTP。请不要粘贴从 SMTP 服务器发送和发送到 SMTP 服务器的内容,因为它们是 base64 编码的。这意味着您将在 base64 中显示您的用户名和密码。 如果你解码VXNlcm5hbWU6,你应该得到Username:。而你的回复bWljcm90ZWNjb25zdWx0aW5nQG91dGxvb2suY29t会被解码为microtecconsulting@outlook.com

所以,我认为您需要更改密码,因为您已在问题中透露。您可能需要检查您的设置。

【讨论】:

  • 感谢您告诉我,我将更改密码。但是,当查看解码的 base64 时,我的密码是正确的,但我仍然收到此错误。
  • 经过很长时间,我意识到这是第一行,如果响应:
猜你喜欢
  • 1970-01-01
  • 2012-07-14
  • 1970-01-01
  • 2019-11-25
  • 1970-01-01
  • 2014-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多