2020年12月20日星期日

PHPMailer sending email but recipient doesn't receive it

I've been trying to use PHPMailer to send emails, but I'm getting and error message that It cant authenticate, even though there's nothing wrong with the email credentials. If I comment out "$mail->isSMTP();" I no longer get the error message, but the email is never received. I can't find the problem. I'm running the code on localhost. I appreciate any help! Here are both the error I get and my code right after:

2020-12-21 01:01:08 SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful [HE1PR0802CA0002.eurprd08.prod.outlook.com] 2020-12-21 01:01:08 SMTP ERROR: Password command failed: 535 5.7.3 Authentication unsuccessful [HE1PR0802CA0002.eurprd08.prod.outlook.com] SMTP Error: Could not authenticate. 2020-12-21 01:01:08 CLIENT -> SERVER: QUIT 2020-12-21 01:01:08 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel SMTP Error: Could not authenticate. Message could not be sent. Mailer Error: SMTP Error: Could not authenticate.

<?php    use PHPMailer\PHPMailer\PHPMailer;  use PHPMailer\PHPMailer\Exception;  use PHPMailer\PHPMailer\SMTP;    require './PHPMailer/src/Exception.php';  require './PHPMailer/src/PHPMailer.php';  require './PHPMailer/src/SMTP.php';    function mailPassword($email_address)  {      // 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.office365.com';                    // Set the SMTP server to send through          $mail->SMTPAuth   = true;                                   // Enable SMTP authentication          $mail->Username   = 'myemail@hotmail.com';                     // SMTP username          $mail->Password   = 'mypassword';                               // SMTP password          $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged          $mail->Port       = 587;                                    // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above            //Recipients          $mail->setFrom('myemail@hotmail.com', 'Mailer');          $mail->addAddress($email_address);            // 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';            echo '<p id="info">Message sent!</p>';      } catch (Exception $e) {          echo '<p id="info">Message could not be sent!</p>';      }  }  
https://stackoverflow.com/questions/65386355/phpmailer-sending-email-but-recipient-doesnt-receive-it December 21, 2020 at 09:07AM

没有评论:

发表评论