【发布时间】:2019-07-25 11:42:16
【问题描述】:
我有 Webuzo VPS 并想使用 PHPMailer 库。
我用以下设置做到了:
在 php.ini 中,我写了 extension=openssl.so 在 PHP 扩展中,所有模块都已经设置好了。
这是我动态发送电子邮件的代码:
require '../vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->Portgiven = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "vector41line6@gmail.com";
$mail->Password = "password";
$mail->setFrom('vector41line6@gmail.com', 'vector 41 line6');
$mail->addReplyTo('vector41line6@gmail.com', 'vector 41 line6');
$mail->addAddress($email);
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Vector 41 Recruitment';
$mail->Body = "some messages";
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
它给出错误:SMTP access error。我该怎么办?
注意。我的代码在 XAMPP 应用程序中运行良好,所以我认为这不是问题。
错误信息
2019-03-04 08:02:14 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP a5sm6779032pgv.12 - gsmtp
2019-03-04 08:02:14 CLIENT -> SERVER: EHLO 192.168.88.120
2019-03-04 08:02:14 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [180.249.242.237]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2019-03-04 08:02:14 CLIENT -> SERVER: STARTTLS
2019-03-04 08:02:14 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2019-03-04 08:02:14 CLIENT -> SERVER: QUIT
2019-03-04 08:02:14
2019-03-04 08:02:14
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
【问题讨论】:
-
您遇到了什么 SMTP 访问错误? Gmail 可能有点挑剔,如果您没有正确使用访问代码,则会将您拒之门外。
-
只是 SMTP 连接失败。
-
本地设置正常
-
我认为我的代码不是问题所在。因为在本地 xampp 中工作正常。