Как исправить ошибку при отправке данных на почту через PHPMailer?

Есть сайт, выходит такая ошибка
2023-11-29 17:45:16 SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP Error: Could not connect to SMTP host. Failed to connect to server
Message could not be sent.Mailer Error: SMTP Error: Could not connect to SMTP host. Failed to connect to serverSMTP server error: Failed to connect to server SMTP code: 110 Additional SMTP info: Connection timed out
Вот php config
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require './PHPMailer/Exception.php';
require './PHPMailer/PHPMailer.php';
require './PHPMailer/SMTP.php';


$phone = $_POST['user__phone'];
$gift = $_POST['user__gift'];
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2; // Enable verbose debug output
    $mail->isSMTP(); // Set mailer to use SMTP
    $mail->Host = 'smtp.mail.ru'; // Specify main and backup SMTP servers
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = 'testwheelwebweb@mail.ru'; // Ваш логин от почты с которой будут отправляться письма
    $mail->Password = '***"'; // Ваш пароль от почты с которой будут отправляться письма
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465; // TCP port to connect to / этот порт может отличаться у других провайдеров
    //Recipients
    $mail->setFrom('testwheelwebweb@mail.ru', 'Mailer'); //This is the email your form sends From
    $mail->addAddress('originalwyse@gmail.com', 'Joe User'); // Add a recipient address
    //Content
    $mail->isHTML(true); // Set email format to HTML
    $mail->Subject = 'Вы выиграли приз с колеса фортуны';
    $mail->Body    = '' .$name . ' оставил заявку, его телефон ' .$phone. '<br>Почта этого пользователя: ' .$email;
    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>
  • Вопрос задан
  • 256 просмотров
Пригласить эксперта
Ответы на вопрос 1
ThunderCat
@ThunderCat Куратор тега PHP
{PHP, MySql, HTML, JS, CSS} developer
Как отправить письмо с сайта через smtp.mail.ru?
Вообще то гуглится в 3 секунды...
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы