[Fixed] PHPMailer SMTP Error: Could not connect to SMTP host.
This error is common while using PHPMailer with upgrader version >5.6. In lower versions its working fine. But when using greater than 5.6 version possibly we got this error .
PHPMailer SMTP Error: Could not connect to SMTP host.
I have quick solution after lot of r&d. This solution may help you solve this problem. Check out this code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
$mail->isSMTP(); //$mail->SMTPDebug = 2; $mail->Host = 'smtp.gmail.com'; // Specify main and backup server $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'youremail@gmail.com'; // SMTP username $mail->Password = 'XXXXXX'; $mail->SMTPSecure = 'tls'; $mail->Port = 25; $mail->Subject = $subject; $mail->Body = $message; $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); $mail->setFrom('youremail@gmail.com', 'Name'); $mail->addAddress($email); $mail->isHTML(true); if($mail->send()) { echo 'Message sent!!'; } |
In this sample code include this code will work perfectly.
1 2 3 4 5 6 7 |
$mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); |
Thank you for visiting.