SMTP配置在生产中不起作用 [英] SMTP configuration not working in production

查看:173
本文介绍了SMTP配置在生产中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在提交表单时发送电子邮件.我正在使用PHPMailer通过以下配置发送邮件.

I'm trying to send an email when a form is submitted. I'm using PHPMailer to send the mail using the below configuration.

$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'mail.example.in'; 
$mail->Port = 25; 
$mail->SMTPAuth = true;
$mail->Username = 'user@example.in'; 
$mail->Password = 'password'; 

$mail->setFrom("user@example.in" , "User");
$mail->addAddress('receiver@example.in', 'Receiver');
$mail->addBCC('anotheruser@somedomain.com', 'Another user');
$mail->AddReplyTo('user@example.in', 'User');

$mail->isHTML(true);

$mail->Subject = $subject;
$mail->Body    = $message;
if($mail->send())
    echo "Your request has been received. We will soon contact you.";
else echo "Unable to send your request. Please try again";

这在localhost中可以正常工作.但是,当我将其部署到服务器(example.in)时,出现以下异常.

This works fine in localhost. But, when I deploy it to my server (example.in) I get the below exception.

SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

-编辑-

我尝试使用telnet命令连接到SMTP服务器,但无法添加收件人.我收到以下错误?

I tried connecting to the SMTP server using telnet command, but I'm unable to add the recipient. I get the below error?

Last login: Fri Sep 16 11:08:06 on ttys000
admin:~ admin$ telnet mail.example.in 25
Trying 111.91.153.112...
Connected to mail.example.in.
Escape character is '^]'.
220 fbs-ho-mailserver.example.in ESMTP Service (Lotus Domino Release 8.5.3FP3) ready at Fri, 16 Sep 2016 11:36:01 +0530
HELO example.in
250 fbs-ho-mailserver.example.in Hello example.in ([111.91.127.222]), pleased to meet you
MAIL from: marketing@example.in
250 marketing@example.in... Sender OK
RCPT to: john.hh@gmail.com
554 Relay rejected for policy reasons.

-编辑-

我能够在Outlook中设置此帐户.我真的很困惑.

I was able to setup this account in outlook. I'm really confused what's happening.

推荐答案

您的错误提示:

SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

因此,让我们看一下 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting :

"SMTP错误:无法连接到SMTP主机."

这也可能显示为SMTP connect()失败或Called Mail()没有 连接到调试输出.这通常被报告为PHPMailer 问题,但几乎总是归因于本地DNS故障,防火墙 阻止(例如GoDaddy所做的)或您本地的其他问题 网络.这意味着PHPMailer无法联系SMTP服务器 您已经在Host属性中指定了,但没有确切说明原因. 也可能是由于未加载openssl扩展名引起的(请参阅 下面的加密说明.

"SMTP Error: Could not connect to SMTP host."

This may also appear as SMTP connect() failed or Called Mail() without being connected in debug output. This is often reported as a PHPMailer problem, but it's almost always down to local DNS failure, firewall blocking (for example as GoDaddy does) or other issue on your local network. It means that PHPMailer is unable to contact the SMTP server you have specified in the Host property, but doesn't say exactly why. It can also be caused by not having the openssl extension loaded (See encryption notes below).

讨论了一些诊断此错误来源的技术 以下.

Some techniques to diagnose the source of this error are discussed below.

美国最受欢迎的托管服务提供商GoDaddy规定非常严格(以至于 发送电子邮件变得几乎毫无用处的限制).他们封锁 到所有服务器(端口除外)的端口25、465和587的出站SMTP 自己的.这个问题是许多令人沮丧的问题的主题 堆栈溢出.如果您发现脚本可以在本地计算机上运行, 但是当您将其上传到GoDaddy时不会发生这种情况 给你. GoDaddy对该解决方案的记录非常差:您 必须通过其服务器发送,并且还禁用所有安全性 功能,用户名和密码(很好,是吗?!),为您提供此配置 对于PHPMailer:

Popular US hosting provider GoDaddy imposes very strict (to the point of becoming almost useless) constraints on sending email. They block outbound SMTP to ports 25, 465 and 587 to all servers except their own. This problem is the subject of many frustrating questions on Stack Overflow. If you find your script works on your local machine, but not when you upload it to GoDaddy, this will be what's happening to you. The solution is extremely poorly documented by GoDaddy: you must send through their servers, and also disable all security features, username and password (great, huh?!), giving you this config for PHPMailer:

$mail->isSMTP();
$mail->Host = 'relay-hosting.secureserver.net';
$mail->Port = 25;
$mail->SMTPAuth = false;
$mail->SMTPSecure = false;

GoDaddy还拒绝发送带有任何aol的发件人地址的邮件, gmail,yahoo,hotmail,live,aim或msn域(请参阅其文档).这 是因为所有这些域都部署了SPF和DKIM反伪造 措施,伪造您的住址是伪造的.

GoDaddy also refuses to send with a From address belonging to any aol, gmail, yahoo, hotmail, live, aim, or msn domain (see their docs). This is because all those domains deploy SPF and DKIM anti-forgery measures, and faking your from address is forgery.

您可能会发现切换到更开明的主机更容易 提供商.

You may find it easier to switch to a more enlightened hosting provider.

这篇关于SMTP配置在生产中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆