Aak*_*ash 21 php email smtp phpmailer
我正在尝试在提交表单时发送电子邮件.我正在使用PHPMailer使用以下配置发送邮件.
$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";
Run Code Online (Sandbox Code Playgroud)
这在localhost中工作正常.但是,当我将它部署到我的服务器(example.in)时,我得到以下异常.
SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Run Code Online (Sandbox Code Playgroud)
- 编辑 -
我尝试使用telnet命令连接到SMTP服务器,但我无法添加收件人.我收到以下错误?
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.
Run Code Online (Sandbox Code Playgroud)
- 编辑 -
我能够在Outlook中设置此帐户.我真的很困惑发生了什么.
你的错误说:
SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Run Code Online (Sandbox Code Playgroud)
那么让我们看看https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting:
“SMTP 错误:无法连接到 SMTP 主机。”
这也可能在调试输出中显示为 SMTP connect() 失败或 Called Mail() 未连接。这通常被报告为 PHPMailer 问题,但几乎总是由于本地 DNS 故障、防火墙阻止(例如 GoDaddy 所做的)或本地网络上的其他问题而导致。这意味着 PHPMailer 无法联系您在 Host 属性中指定的 SMTP 服务器,但没有确切说明原因。这也可能是由于未加载 openssl 扩展引起的(请参阅下面的加密说明)。
下面讨论一些诊断此错误来源的技术。
去吧爸爸
美国流行的托管提供商 GoDaddy 对发送电子邮件施加了非常严格(几乎变得几乎无用)的限制。他们阻止向除他们自己的服务器之外的所有服务器发送到端口 25、465 和 587 的出站 SMTP。这个问题是 Stack Overflow 上许多令人沮丧的问题的主题。如果您发现脚本在本地计算机上可以运行,但在将其上传到 GoDaddy 时却不能运行,那么您就会遇到这种情况。GoDaddy 对该解决方案的记录非常少:您必须通过他们的服务器发送,并且还禁用所有安全功能、用户名和密码(很好,是吧?!),为您提供 PHPMailer 的以下配置:
Run Code Online (Sandbox Code Playgroud)$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 防伪造措施,伪造您的发件人地址就是伪造。
您可能会发现更容易切换到更开明的托管提供商。