如何在Webuzo中使用PHPMailer VPS
How to use PHPMailer in Webuzo VPS
我有 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
这不是代码问题;这是一个环境问题。由于实时服务器上的 CA 证书包已过期,您的证书验证失败。您的本地副本没问题,这就是它在那里工作的原因。您的连接没有被您的 ISP 阻止。
按照 how to update your CA bundle 上的故障排除指南中的建议进行操作。简而言之,确保您的服务器包是最新的,如果是,请自行更新您的 CA 包,或使用 Certainty 包来维护您自己的副本。
我有 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
这不是代码问题;这是一个环境问题。由于实时服务器上的 CA 证书包已过期,您的证书验证失败。您的本地副本没问题,这就是它在那里工作的原因。您的连接没有被您的 ISP 阻止。
按照 how to update your CA bundle 上的故障排除指南中的建议进行操作。简而言之,确保您的服务器包是最新的,如果是,请自行更新您的 CA 包,或使用 Certainty 包来维护您自己的副本。