MaxLucky
@MaxLucky

Как решить ошибку при отправке методом SMTP через PHP mailer?

Пытаюсь настроить рассылку методом "SMTP" через php mailer. Через AMS - всё работает. В чём может быть проблема?

Код:

<?php
/**
* This example shows making an SMTP connection with authentication.
*/
//Import the PHPMailer class into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require 'vendor/autoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Set the hostname of the mail server
$mail->Host = 'IP сервера';
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 587;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = 'newlife@мой домен.ru';
//Password to use for SMTP authentication
$mail->Password = 'пароль';
//Set who the message is to be sent from
$mail->setFrom('newlife@мой домен.ru', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('newlife@мой домен.ru', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('q-ewqewq@bk.ru', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent!';
}

Появляется ошибка:

2018-06-29 13:51:28 SERVER -> CLIENT: 220 mail.мой домен.ru ESMTP Exim 4.90_1 Fri, 29 Jun 2018 16:51:28 +0300
2018-06-29 13:51:28 CLIENT -> SERVER: EHLO mail.мой домен.ru
2018-06-29 13:51:28 SERVER -> CLIENT: 250-mail.мой домен.ru Hello мой домен.ru [IP Сервера]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN CRAM-MD5250-CHUNKING250-STARTTLS250 HELP
2018-06-29 13:51:28 CLIENT -> SERVER: STARTTLS
2018-06-29 13:51:28 SERVER -> CLIENT: 220 TLS go ahead
SMTP Error: Could not connect to SMTP host.
2018-06-29 13:51:28 CLIENT -> SERVER: QUIT
2018-06-29 13:51:28
2018-06-29 13:51:28
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubl...
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubl...
  • Вопрос задан
  • 755 просмотров
Пригласить эксперта
Ответы на вопрос 1
glem1337
@glem1337
Может поздно, но у меня была такая же проблема. Решение которое мне помогло:
$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);
Ответ написан
Ваш ответ на вопрос

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

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