我正在尝试使用PHPMailer发送验证电子邮件并向我的网站完成新的用户请求。当我在本地测试时,一切正常,我从outlook.com电子邮件帐户收到了预期的电子邮件。但是,只要我上传到我的webhost服务器,它就不起作用。由于我使用的是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.
这是我的php处理新用户表单请求并使用PHPMailer发送电子邮件:
<?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();
?>
我不明白的是,就我的本地服务器到远程服务器而言,没有什么真正改变(也不应该),但是当我远程运行代码时它无法正常工作。我在PHPMailer包的顶部添加了include_path,但我知道这是有效的,因为我需要它在下面。我还需要在db_connect.php中更改我的数据库设置,但我知道它也有效,因为它创建了DB记录。任何帮助将不胜感激。谢谢,约翰
答案 0 :(得分:2)
由于我没有足够的评论意见,我会在这里告诉你。问题可能在于您的身份验证,因为您可以正常连接到SMTP。请不要粘贴从SMTP服务器发送的内容,因为它们是base64编码的。这意味着您在base64中显示您的用户名和密码。
如果您解码VXNlcm5hbWU6
,则应获得Username:
。您的回复bWljcm90ZWNjb25zdWx0aW5nQG91dGxvb2suY29t
将被解码为microtecconsulting@outlook.com
。
所以,我认为您需要更改密码,因为您已在问题中透露。您可能想要检查您的设置。
答案 1 :(得分:1)
您的ISP正在将您重定向到他们自己的邮件服务器。
在您的脚本中,您指定要连接到smtp-mail.outlook.com
,但是您要连接到a2ss15.a2hosting.com
,我怀疑它与Outlook.com无关,但与a2hosting有关的一切都与您有关ISP。阅读主机提供的任何文档,并打开支持票据以禁用此重定向。
the PHPMailer troubleshooting guide中提到了这一点。
这也正是为什么你应该启用加密和验证证书(PHP 5.6中的默认值,但不是之前),因为他们正在做的是一个中间人攻击,并且有效地揭示了你的这个未知的密码(幸运的是在这种情况下不太知名)第三方。