SMTP错误:无法连接到SMTP主机 [英] SMTP Error: Could not connect to SMTP host
问题描述
我有此代码,并且在我的本地服务器上都可以正常工作.电子邮件发送没有任何问题.
I have this code, and all works well in my local server. The email is sent without any problem.
但是现在我将内容传递到Web服务器,并且出现此错误...
But now I pass the content to webserver, and I get this error...
SMTP Error: Could not connect to SMTP host.
服务器中启用了SSL.正确吗?那么,有什么问题呢?
SSL is enable in the server..correct? so, what is the problem?
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->Username = "dnteiro"; // GMAIL username
$mail->Password = "xxx"; // GMAIL password
推荐答案
听起来您的Web主机正在阻止与smtp.gmail.com:465的出站连接.建议:
It sounds like your web host is blocking outbound connections to smtp.gmail.com:465. Suggestions:
-
验证:如果您具有对网络托管服务器的外壳/终端访问权限,请尝试进行telnet测试,以验证它们是否实际上已阻止了此操作.运行
telnet smtp.gmail.com 465
联系人:致电或给您的托管服务提供商发送电子邮件,并找出它们为出站中继提供什么SMTP服务器.确保他们知道您要将@gmail.com
地址用作发件人/答复人地址.
Contact: Call or email your hosting provider and find out what SMTP server they provide for outbound relay. Make sure they know you want to use your @gmail.com
address as the From/Reply-to address.
更新代码:主机为您提供其他邮件服务器后,请更新代码,然后重试.
Update code: Once your host provides you with a different mail server, update your code and try again.
如果您的Web主机根本不允许来自其服务器的出站中继,那么如果这是您的应用程序所必需的,那么您需要查看切换主机.
If your web host doesn't allow outbound relay from its servers at all, then you need to look at switching hosts, if this is a requirement for your application.
这篇关于SMTP错误:无法连接到SMTP主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!