I am trying to send a mail via phpMailer but I got below error
2019-03-28 10:54:00 SMTP ERROR: Failed to connect to server: (0) 2019-03-28 10:54:00 SMTP connect() failed. Mailer Error: SMTP connect() failed.
I referred below links
https://stackoverflow.com/questions/43815571/mailer-error-smtp-connect-failed
https://stackoverflow.com/questions/21088062/phpmailer-smtp-connection-error
https://stackoverflow.com/questions/43999573/phpmailer-smtp-connect-error
https://stackoverflow.com/questions/36735979/mailer-error-smtp-connect-failed
https://stackoverflow.com/questions/30476024/smtp-connect-failed-phpmailer
but after implementing the solution as mention in the above links, getting the same error.
I tried with PHP mail() function for the same credential, it's working but I wanted to send a mail via SMTP.
here is my code
require('mail/class.phpmailer.php');
require('mail/PHPMailerAutoload.php');
$mail = new PHPMailer;
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Mailer = "smtp";
$mail->Host = 'mail.example.com';
$mail->SMTPAuth = true;
$mail->Username = 'From@example.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('From@example.com', 'from');
$mail->addAddress('To@example.com', 'To');
$mail->isHTML(true);
$mail->Subject = 'subject';
$mail->Body = 'This is message';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}