Timeout when sending message via SMTP using PHPMailer?

There is code:
$mail = new PHPMailer;
 $mail->CharSet = 'UTF-8';

// SMTP settings
$mail->isSMTP();
 $mail->SMTPAuth = true;
 $mail->SMTPDebug = 3;

 $mail->Host = 'smtp.yandex.com';
 $mail->Port = 465;
 $mail->Username = '***@yandex.ru';
 $mail->Password = '***';



// From whom
 $mail->setFrom('***i@yandex.ru', 'Snipp.ru');

// Who
 $mail->addAddress('pavel.dymok@gmail.com', 'John DOE');

// The subject of the email
 $mail->Subject = "Subject";

// The body of the email
 $body = '<p><strong>"Hello, world!" </strong></p>';
$mail->msgHTML($body);

 //send the message, check for errors
 if (!$mail->send()) {
 echo 'Mailer Error:' . $mail->ErrorInfo;
 } else {
 echo 'Message sent!';
 }

AJAX turning, in the end, after 3 minutes of waiting just ends the script execution time, in the console:
<br / >2019-08-07 07:44:09 Connection: opening to smtp.yandex.com:465, timeout=300, options=array()<br>
2019-08-07 07:44:09 Connection opened<br>
<br />
<b>Fatal error</b>: Maximum execution time of 180 seconds exceeded in <b>D:\OSPanel\domains\blockchain.mcdir.local\vendor\phpmailer\phpmailer\src\SMTP.php</b> on line <b>1125</b><br />

Tried from the computer hosting with SMTP server mail.ru ping to the SMTP server is. What else could be the problem? Already all head broke.
March 25th 20 at 13:44
1 answer
March 25th 20 at 13:46
Solution
Try setting up a secure connection:
$mail->SMTPSecure = 'tls';
465 for the port should be SMTPSecure = 'ssl'. - Esperanza.Feeney commented on March 25th 20 at 13:49
@Esperanza.Feeney, perhaps, and certainly you can learn from Yandex. - Rylan_Witting commented on March 25th 20 at 13:52
@Rylan_Witting, they have SSL on 465, but as with all public. - Esperanza.Feeney commented on March 25th 20 at 13:55
@Esperanza.Feeney, do not argue. The answer is that you want to configure. - Rylan_Witting commented on March 25th 20 at 13:58
Thank you, it worked. - orville95 commented on March 25th 20 at 14:01

Find more questions by tags PHPMailerSMTPPHP