Php 端口465似乎已打开,但仍无法发送邮件

Php 端口465似乎已打开,但仍无法发送邮件,php,smtp,gmail,phpmailer,Php,Smtp,Gmail,Phpmailer,我已打开服务器上的端口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 但当我尝试发送邮件时: $mail = new PHPMailer (); $mail->IsSMTP (); $mail->SMTPDebug = 1; $mai

我已打开服务器上的端口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

但当我尝试发送邮件时:

$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
SMTP->错误:无法连接到服务器:连接超时(110)

以下发件人地址失败:Gmail用户名:未连接就调用了邮件()
任何帮助都将不胜感激

请通过或。。我想这与您的错误有关。

谷歌的SMTP服务器需要身份验证,下面介绍如何设置:
  • SMTP服务器(即发送邮件):

  • SMTP用户名:您的完整Gmail或谷歌应用电子邮件地址。example@gmail.com 或example@yourdomain.com)

  • SMTP密码:您的Gmail或谷歌应用程序电子邮件密码

  • SMTP端口:465

  • SMTP需要TLS/SSL:是 为了在你发送的Gmail或Google应用程序中存储发送电子邮件的副本 文件夹中,登录您的Gmail或Google Apps电子邮件设置并:

  • 单击转发/IMAP选项卡并向下滚动到IMAP访问 节:IMAP必须启用才能正确发送电子邮件 已复制到已发送文件夹中


  • 发送限制 谷歌限制用户可以通过其便携式SMTP服务器发送的邮件量此限制将每天发送的邮件数量限制为99封电子邮件;并在达到限制后24小时内自动取消限制



    来源:

    事实证明,digitalocean已经阻止了为新用户发送电子邮件。联系了他们,现在开始工作了。希望这对某人有所帮助。

    出于好奇,你的用户名是不是
    gmailusername
    和密码是不是
    gmailpassword
    ?不,这些只是替代品。你的服务器在路由器后面吗?服务器是digitalocean,不是。你的防火墙真的进行出口过滤吗?我建议在587上使用TLS,而不是在465上使用过时的SSL。您可以随时检查它是否是您的防火墙,只需将其完全禁用片刻。设置
    SMTPDebug=4
    以获取连接信息。在587上使用TLS,而不是在465上使用SSL,后者已被弃用15年。