May 25, 2010
We struggled with this for days, no exaggeration! And I googled like crazy, but never got an answer, and only accidentally stumbled onto the solution in the end.
The problem was that when I set up my phpmailer (5.1) to send mails using my gmail account, via google smtp (smtp.google.com), the mailer program worked. But if I tried other SMTP servers, I got the following error:
fsockopen() [function.fsockopen]: unable to connect to mail.mydomain.com:25 (Connection refused)
Now all the other SMTP servers were working with those details in other programs such as Outlook, but when using phpmailer the error kept saying that we can’t connect with the server. So we contacted the server IT guys and asked them why the server won’t allow us to make a connection, but when they monitored the server, they found that no connection attempts were even being made… which means we were getting the wrong error from phpmailer!
So what was the solution?
In phpmailer’s setup you can set what type of emailing method you wish to use — SMTP, sendmail or mail. You can set this using the functions
IsSendmail(). Now we used SMTP so I called
IsSMTP() to set the method to SMTP but nothing worked. So I changed the public variable myself like this :
$phpmailerinstance->Mailer = "SMTP"
And all of a sudden it worked!
So what was the catch? It was the CAPITAL LETTERS ! The
IsSMTP() function sets the
$Mailer variable to ‘smtp’ in lowercase which created problems, but when I manually set it to ‘SMTP’ in uppercase, it worked!
Some SMTP servers (like smtp.google.com) can accept SMTP requests if you set the method to ‘smtp’ in lower case, but all SMTP servers accept the request in upper case “SMTP”
I really hope this saves someone from the trouble I went through to figure it out!