简体   繁体   中英

Port 465 seems open, but still cannot send mail

I have opened the port 465 on my server:

iptables -A INPUT -p tcp -m tcp --dport 465 -j ACCEPT
iptables-save | sudo tee /etc/sysconfig/iptables
service iptables restart

And I can see the port is ACCEPT when I run iptables -L -n

But still when I try to send mail:

$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();

I get the following error:

SMTP -> ERROR: Failed to connect to server: Connection timed out (110)
<br />The following From address failed: gmailusername : Called Mail() without being connected

Any help would be appreciated!

Turns out, digitalocean had blocked sending emails for new users. Contacted them and now it's working. Hope this helps someone.

Google's SMTP server requires authentication, so here's how to set it up:

  1. SMTP server (ie, outgoing mail): smtp.gmail.com

  2. SMTP username: Your full Gmail or Google Apps email address (eg example@gmail.com or example@yourdomain.com)

  3. SMTP password: Your Gmail or Google Apps email password

  4. SMTP port: 465

  5. SMTP TLS/SSL required: yes
    In order to store a copy of outgoing emails in your Gmail or Google Apps Sent folder, log into your Gmail or Google Apps email Settings and:

  6. Click on the Forwarding/IMAP tab and scroll down to the IMAP Access section: IMAP must be enabled in order for emails to be properly copied to your sent folder .


Sending Limits

Google limits the amount of mail a user can send, via its portable SMTP server. This limit restricts the number of messages sent per day to 99 emails ; and the restriction is automatically removed within 24 hours after the limit was reached.


Source: How To Use Google's SMTP Server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM