Сообщение не может быть отправлено. Ошибка почтовой программы: сбой подключения SMTP (). https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting - PullRequest
0 голосов
/ 07 мая 2020

enter image description here

Я включил IMAP в настройках Gmail.

enter image description here

Это запрос сброса. php

 <?php

use PHPMailer\PHPMailer\PHPMailer;

use PHPMailer\PHPMailer\Exception;

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

if(isset($_POST["email"])){

    $emailTo=$_POST["email"];


   $mail = new PHPMailer(true);

try {
    //Server settings
    $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   = 'username@gmail.com';                     // SMTP username
    $mail->Password   = 'password';   
    $mail->SMTPSecure = 'ssl';                             // SMTP password
    $mail->Port       = 465;                                    // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above

    //Recipients
    $mail->setFrom('username@gmail.com', 'Pconcio Dental Clinic');
    $mail->addAddress("$emailTo");     // Add a recipient
    $mail->addReplyTo('no-reply@example.com', 'No-reply');
    // Content


    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Your Password reset link';
    $mail->Body    = "<h1>You requested a password reset</h1>
                         Click <a href='#'>this link </a> to do so";
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

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

<form method="POST">
<input type="text" name="email" placeholder="Email" autocomplete="off">
<br>
<input type="submit" name="submit" value="Enter">
</form>

Это ошибка:

Message could not be sent. Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Я пытаюсь отправить ссылку на страницу сброса пароля по электронной почте в Gmail, но ошибка связана с подключением SMTP. Что я сделал не так в коде. Извините, я новичок :)

...