【发布时间】: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