Saturday, May 17, 2014

Shopping Cart with phpmailer - Unable to connect to server / Could not instantiate mail function in PHPMailer

Shopping Cart with phpmailer - Could not connect to server /  Could not instantiate mail function in PHPMailer
Environment: Centos 6.4 / 


I spent a long time on this fucking damn problem, so I hope it can give you some clues on your situation.

Symptoms:
I configured the smtp servver with port number, but it keep pop me a message saying could not connect,
I able to telnet the SMTP server on the machine, and send mail in command mode, iptables allows those traffic,
but, phpmailer keep fail me no matter the mode I configure [SMTP / mail / sendmail]

I don't waste your time to read my investigation, let's see the solution

Solution:
It caused by the module SELinux is enabled in Linux, which blocked all the mail sent through httpd

you can checked the status of your system by the following command


plus, you should check the parameter httpd_can_sendmail is off or not.


if SELINUX is enforcing & httpd_can_sendmail is off, that's the reason the connection was failed.
input the command below to turn is on




In my case, the email feature resumed normal, hope it can help you

延伸閱讀 Extended Reading
What is SELinux?
will be answer on my next post.