Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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    --    0.0.0.0/0   0.0.0.0/0   tcp dpt:465
ACCEPT   tcp    --    0.0.0.0/0   0.0.0.0/0   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->IsSMTP();
$mail->SMTPDebug = 1; //!DEV
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';      
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = $emailAddress;
$mail->Password = $emailPassword;
$mail->SetFrom($emailAddress, 'PURCHASE ORDER');
$mail->AddAddress($customerEmail);
$mail->AddAddress($salesEmail); 
$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

2 Answers 2

You've told your server to accept incoming connections on port 465, but then you're also telling it to connect to smtp.gmail.com 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
1  
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

 
discard

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.