【问题标题】:How to use PHPMailer in Webuzo VPS如何在 Webuzo VPS 中使用 PHPMailer
【发布时间】: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 中工作正常。

标签: php email smtp phpmailer


【解决方案1】:

这不是代码问题;这是环境问题。由于您的实时服务器上的 CA 证书包已过期,您的证书验证失败。您的本地副本没问题,这就是它在那里工作的原因。您的连接没有被您的 ISP 阻止。

遵循how to update your CA bundle 上的故障排除指南中的建议。简而言之,确保您的服务器包是最新的,如果是,请自行更新您的 CA 包,或使用确定性包来维护您自己的副本。

【讨论】:

    猜你喜欢
    • 2017-09-10
    • 2016-09-26
    • 1970-01-01
    • 2022-06-16
    • 1970-01-01
    • 2021-03-21
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    相关资源
    最近更新 更多