【发布时间】:2014-12-08 07:58:58
【问题描述】:
我已经在我的服务器上打开了 465 端口:
iptables -A INPUT -p tcp -m tcp --dport 465 -j ACCEPT
iptables-save | sudo tee /etc/sysconfig/iptables
service iptables restart
当我运行 iptables -L -n 时,我可以看到端口是 ACCEPT
但是当我尝试发送邮件时:
$mail = new PHPMailer ();
$mail->IsSMTP ();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = "gmailusername";
$mail->Password = "gmailpassword";
$mail->SetFrom ( $from, $title );
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress ( $to );
$mail->Send();
我收到以下错误:
SMTP -> ERROR: Failed to connect to server: Connection timed out (110)
<br />The following From address failed: gmailusername : Called Mail() without being connected
任何帮助将不胜感激!
【问题讨论】:
-
出于好奇,您的用户名
gmailusername和密码gmailpassword? -
不,这些只是替代品。
-
你的服务器在路由器后面吗?
-
服务器是digitalocean,没有。
-
你的防火墙真的做出口过滤吗?我建议在 587 上使用 TLS,而不是在 465 上使用过时的 SSL。您可以随时通过完全禁用它来检查它是否是您的防火墙。设置
SMTPDebug = 4获取连接信息。