PHP Mailer - email does not reach the inbox

Asked

Viewed 153 times

0

I started using phpmailer by the very example of the git page, it gives everything ok, echo goes to "message sent", but the message does not arrive in the email box, someone can say why?

<?php

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

$mail = new PHPMailer\PHPMailer\PHPMailer();
try {

$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Username = '[email protected]';
$mail->Password = '******';
$mail->Port = 587;

$mail->setFrom('[email protected]', 'Cairo');
$mail->addAddress('[email protected]', 'Yara');
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');

$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 enviada';
 } catch (Exception $e) {
 echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
} 
?>
Show 2 more comments

1 answer

1


To send emails you have to enable the option to allow less secure applications to use the account. To enable this option click on your gmail profile image, click on "google account"

Then in the menu on the left click on "Security" Passo2

Then scroll the page until you find the "less secure app access" option and click "enable access" Passo3 I believe that with this I can send the emails

  • Better organize your response. Place some images of the pages and where to click.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.