I have this weird problem with PHPMailer. The exact same code works on my localhost with PHP5.6 installed, but when i host it with Cpanel it fails. I confirmed that SSL is enabled by doing echo (extension_loaded('openssl')?'SSL loaded':'SSL not loaded')."\n";
.
$m = new PHPMailer;
$m->isSMTP();
$m->SMTPAuth = true;
/* $m->SMTPDebug =4; */
$m->Host = 'smtp.gmail.com';
$m->Username = '*********@gmail.com';
$m->Password= '*********';
$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->isHTML();
$m->Subject = 'Contact Form';
$m->Body='Sender: ' . $fields['name'] . ' ('.$fields['email'].') <p>' . $fields['message']. '</p>';
$m->FromName ='From Website';
$m->CharSet = 'UTF-8';
$m->AddAddress('**********@gmail.com','********');
if($m->send()){
echo "<script language='javascript'> alert('Message Sent Succesfully. We'll get back to you soon.'); window.location = '$url';</script>";
die();
}
else{
$errors='Sorry, something went wrong. Please try again later. ' . $m->ErrorInfo;
}
The error i get with $m->ErrorInfo
is:
SMTP connect() failed. https //github.com/phpmailer/phpmailer/wiki/troubleshooting
I tried uncommenting the $m->SMTPDebug =4;
line, but all it says is stuff like
Failed to connect SMTP Server
Any help is appreciated, thanks in advance!