0

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!

4
  • try, $m->SMTPDebug =1;
    – Dave
    Commented Jul 23, 2016 at 5:48
  • SMTP ERROR: Password command failed. Please log in via your web browser and then try again. SMTP Error: Could not authenticate. Which is weird because same code works on 5.6 and sends mail so nothing wrong with my pass.
    – John Boga
    Commented Jul 23, 2016 at 5:53
  • While the code might be the same the senders IP address is different. See PHPMailer - SMTP ERROR: Password command failed when send mail from my server for more details (duplicate). Commented Jul 23, 2016 at 6:24
  • Read the PHPMailer troubleshooting guide which tells you exactly how to diagnose problems like this. If you don't see a link to it in your debug output, you're using an old version.
    – Synchro
    Commented Jul 23, 2016 at 7:15

0

Browse other questions tagged or ask your own question.