1

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!

dsthetics
  • 287
  • 1
  • 7
  • 19

3 Answers3

2

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

dsthetics
  • 287
  • 1
  • 7
  • 19
0

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

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

  2. SMTP username: Your full Gmail or Google Apps email address (e.g. 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

Jonny Henly
  • 4,023
  • 4
  • 26
  • 43