我正在我的大学里做一项任务,他们允许我使用服务器发送外发电子邮件。
我的PHP代码:(我正在使用PHPMailer库)
<?php
require_once 'vendor/autoload.php';
$mail = new PHPMailer();
$mail->SMTPDebug = 3;
$mail->IsSMTP();
$mail->Host = 'mailhub.xxxx.edu.au'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Port = 25;
$mail->SetFrom('no-reply@travnow.com', 'Test');
$mail->Subject = "I hope this works!";
$mail->MsgHTML('Blah');
$address = "xxxxxxx@gmail.com";
$mail->AddAddress($address, "Test");
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
服务台人员说我只需要使用“mailhub.xxxx.edu.au”作为mySMTP服务器,端口25并且身份验证是基于IP的。
但后来我收到了这个错误:
2017-05-17 07:44:08 Connection: opening to mailhub.xxxx.edu.au:25, timeout=300, options=array ( )
2017-05-17 07:44:08 Connection: opened
2017-05-17 07:44:08 SERVER -> CLIENT: 220 mailhub.xxxx.edu.au ESMTP Sendmail 8.15.1/8.15.1; Wed, 17 May
2017 17:44:08 +1000 (AEST)
2017-05-17 07:44:08 CLIENT -> SERVER: EHLO _
2017-05-17 07:44:08 SERVER -> CLIENT: 250-mailhub.xxxx.edu.au Hello infs3202-c25wl.xxxx.net [172.23.83.119] (may be forged), pleased to meet you 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-8BITMIME 250-SIZE 67108864 250-DSN 250-ETRN 250-STARTTLS 250-DELIVERBY 250 HELP
2017-05-17 07:44:08 CLIENT -> SERVER: STARTTLS
2017-05-17 07:44:08 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2017-05-17 07:44:08 CLIENT -> SERVER: EHLO _
2017-05-17 07:44:08 SERVER -> CLIENT: 250-mailhub.xxxx.edu.au Hello infs3202-c25wl.xxxx.net [172.23.83.119] (may be forged), pleased to meet you 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-8BITMIME 250-SIZE 67108864 250-DSN 250-ETRN 250-DELIVERBY 250 HELP
2017-05-17 07:44:08 SMTP Error: Could not authenticate.
2017-05-17 07:44:08 CLIENT -> SERVER: QUIT
2017-05-17 07:44:08 SERVER -> CLIENT: 221 2.0.0 mailhub.xxxx.edu.au closing connection
2017-05-17 07:44:08 Connection: closed 2017-05-17 07:44:08 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
这是我的代码或服务器端的错误吗?
任何指针都将受到赞赏。
答案 0 :(得分:1)
您正在使用smtp Auth方法,因此您可以尝试提供用于验证的用户名和密码:
$mail->Username = "name@gmail.com";
$mail->Password = "super_secret_password";