Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using phpMailer to send off purchase confirmations using a google apps address/smtp. The whole thing was working great on the development box, but now that it's live, it seems that the port I'm using (465) is blocked.

So I edit iptables with:

-A INPUT -p tcp -dport 465 -j ACCEPT  
-A INPUT -p tcp -sport 465 -j ACCEPT

My understanding is that this allows inbound & outbound connections on 465 (correct me if I'm wrong). After restarting iptables:

iptables -nL  
Chain INPUT (policy ACCEPT)
target   prot   opt   source      destination
ACCEPT   tcp    --   tcp dpt:465
ACCEPT   tcp    --   tcp spt:465

However I still receive "Failed to connect to server: Permission denied" as debug from phpMailer. From what I've read, this usually indicates that the port is closed, & evidently that is the case.

Any hints on how to debug this further? Any help would be much appreciated.

In case it helps, here's the php:

$mail = new PHPMailer();        
$mail->SMTPDebug = 1; //!DEV
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';      
$mail->Host = '';
$mail->Port = 465;
$mail->Username = $emailAddress;
$mail->Password = $emailPassword;
$mail->SetFrom($emailAddress, 'PURCHASE ORDER');
$mail->Subject = $subject;
$mail->Body = $body;        
$mail->Send() or die('Error: ' . $mail->ErrorInfo);

*Edit: The mailer works flawlessly on the development server - any advice on ways to compare what may be different? Same OS, same php... I'm stumped!

share|improve this question
Your INPUT policy is ACCEPT so these rules are unnecessary. The packets would be passed anyway. I'm willing to bet that your OUTPUT chain is empty and has an ACCEPT policy too. – Ladadadada Aug 22 '12 at 8:09

You've told your server to accept incoming connections on port 465, but then you're also telling it to connect to which is an outbound connection.

You will need to open the same ports, but on the OUTPUT chain instead of the INPUT one:

-A OUTPUT -p tcp -dport 465 -j ACCEPT  
share|improve this answer
You won't need the -sport rule. The source port will be random and high. – Ladadadada Aug 22 '12 at 8:05
Ladadadada - you're right, I shouldn't try copy-pasting until I've had my second cup of coffee... I removed the sport line. – Jenny D Aug 22 '12 at 8:28

A firewall problem should cause either "The connection was reset" or "The connection timed out" error messages. PHPMailer might be giving you a "Permission denied" error message instead of one of those two but that would be a bad error message. (It wouldn't be the first time I have seen bad error messages.)

If the error message "Failed to connect to server: Permission denied" is helpful, it suggests that you have safe_mode on or you have disallowed opening sockets in your php.ini.

This could also be caused by SELinux. I'm not familiar enough with it to tell you what to do to determine if this is the case or to fix it.

share|improve this answer
Double checked safe_mode = Off, sockets = enabled. – kyebosh Aug 22 '12 at 10:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.