ВНИМАНИЕ SMTP: EOF обнаружен при проверке подключения - PullRequest
0 голосов
/ 06 мая 2020
<?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\SMTP;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';

// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      // Enable verbose debug output
    $mail->isSMTP();                                            // Send using SMTP
    $mail->Host       = 'smtp.gmail.com';                    // Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
    $mail->Username   = 'mygmail@gmail.com';                     // SMTP username
    $mail->Password   = 'mygmailpassword';                               // SMTP password
    $mail->Port       = 465;                                    // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above

    //Recipients
    $mail->setFrom('mygmail@gmail.com', 'Courses');
    $mail->addAddress('mygmail@gmail.com');     // Add a recipient
    $mail->addReplyTo('no-reply@example.com', 'No-reply');
    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>

Это ошибка, которую я получил

2020-05-06 07:59:56 SERVER -> CLIENT:
2020-05-06 07:59:56 SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not authenticate.
SMTP Error: Could not authenticate.
Message could not be sent. Mailer Error: SMTP Error: Could not authenticate.

Я изменил порт с 465 на 587, но это не сработало. Я искал именно эту проблему, но в основном ответ был изменен на порт 465, но это не сработало. Что я сделал не так в коде. Простите, я новичок

1 Ответ

1 голос
/ 06 мая 2020

Попробуйте добавить это. Это решило проблему для меня!

$mail->SMTPSecure = 'ssl';

Убедитесь, что у вас не включена двухэтапная проверка

Стоит отметить, что некоторые SMTP-серверы блокируют соединения. Некоторые серверы SMTP не поддерживают соединения SSL (или TLS).

...