How to resolve 'SMTP Error: Could not connect to SMTP host.' in phpmailer?
First of all, while initiating PHPMailer send in the parameter true
like,
$mailer = new PHPMailer(true);
This will help you to catch and handle exceptions.
Secondly, try this
$mailer->SMTPSecure = 'ssl'; // instead of tls
PHPMailer: Could not connect to SMTP host
$mailer->Host = 'ssl://smtp.gmail.com:465';
PHPMailer + smtp.gmail.com : Could not connect to SMTP host
Just Add the following codes before line code $mail->SMTPDebug
saves the day
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
Related Topics
Preserve Line Breaks from Textarea
Special Characters in Property Name of Object
How to Perform Static Code Analysis in PHP
What's the Difference Between :: (Double Colon) and -≫ (Arrow) in PHP
Download Multiple Files as a Zip-File Using PHP
Get the Last Inserted Id Using Laravel Eloquent
Simple Jquery, PHP and Jsonp Example
Insert Array into MySQL Database With PHP
Max Size of Url Parameters in _Get
Achieve Hierarchy, Parent/Child Relationship in an Effective and Easy Way
Limit Keyword on MySQL With Prepared Statement
PHP Preg_Match to Find Multiple Occurrences
How to Find the PHP.Ini File Used by the Command Line
How to Extend Access Token Validity Since Offline_Access Deprecation