I have a PHP script which send email using PHPMailer library. When I run the script in the SSH using PHP command, it sends email perfectly. But when the request for the same script is coming from a browser, it is failing and giving below error.
2016-12-17 19:41:24 SMTP ERROR: Failed to connect to server: (0) 2016-12-17 19:41:24 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting error
I am not sure what is causing it not work for browser requests.
My script is on AWS and I am using google business email.
Below is my code snippet.
require_once 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->IsHTML(true);
$mail->CharSet = "text/html; charset=UTF-8;";
$mail->SMTPDebug = 2;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "google email address";
$mail->Password = "password";
$mail->From = $email_from;
$mail->FromName = "Name";
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->Body = $message;
$sent = $mail->Send();
I will appreciate any help. Thanks.
EDITED: I have managed to solve the "Module 'curl' already loaded in Unknown on line 0" issue. There were 2 PHP.ini files in the server which was causing the issue. Renaming one PHP.ini resolved the curl loaded issue.
But still I am unable to send email using nobody user. However I can send email using root user.
I have noticed a configuration in the WHM for "Prevent “nobody” from sending mail". By default it was on meaning nobody is not allowed to send email. So, if I turn it off, I should be able to send email using nobody. But not sure why after turning it off still I can not send email using nobody user.
EDITED: When I checked apache server logs, I found below error being generated for each request coming from the browser. Not sure what this error is. I am doing research on this. I will appreciate if anybody is aware of the issue. Thank You! ******************ERROR LOGS******************************* [Tue Dec 20 12:38:45.875892 2016] [ssl:error] [pid 913] (101)Network is unreachable: [client xx.xx.xx.xx:151] AH01974: could not connect to OCSP responder 'ocsp.comodoca.com' [Tue Dec 20 12:38:45.875929 2016] [ssl:error] [pid 913] AH01941: stapling_renew_response: responder error [Tue Dec 20 12:38:46.181171 2016] [ssl:error] [pid 919] (101)Network is unreachable: [client xx.xx.xx.xx:848] AH01974: could not connect to OCSP responder 'ocsp.comodoca.com' [Tue Dec 20 12:38:46.181211 2016] [ssl:error] [pid 919] AH01941: stapling_renew_response: responder error
Thanks for Your Help!