Search code examples
phpemailxamppgmail

PHP XAMPP mail() sent, but not delivered to mailbox


I have problem with mail() function in PHP. I'm using XAMPP. Here are my configuration files:

php.ini

[mail function]

SMTP = smtp.gmail.com
smtp_port = 587
sendmail_from = [email protected]
sendmail_path = C:\xampp\sendmail\sendmail.exe\

sendmail.ini (C:\xampp\sendmail\sendmail.ini)

[sendmail]

smtp_server = smtp.gmail.com
smtp_port = 587
error_logfile = error.log
debug_logfile = debug.log
auth_username = [email protected]
auth_password = my_password
force_sender = [email protected]

Here's my code:

<?php

$to= "[email protected]";
$subject = "Title";
$messages= "Lorem ipsum dolor sit amet.";

if( mail($to, $subject, $messages) ) {
  echo "Email sent!";
} else {
  echo "Not sent!";
}

?>

The program is returning Email sent! message, but mail is not delivering to my mailbox. I've already tried changing port in php.ini and sendmail.ini to 465 and nothing changed.

Do you have any idea?


EDIT:

I think, I,ve found my this php log. It was in polish (my system default leanguage), so the translation can be not perfect - sorry for that. Here it is:

Unable to find description for Event ID 2 from PHP-7.4.6 source. Either the component causing this event is not installed on the local computer or the installation is damaged. You can install or repair the component on your computer.

If the event is from a different computer, you may need to save the display information along with the event.

The following information was attached to the event:

php
mail () on [C: \ xampp \ htdocs \ mail.php: 8]: To: [email protected] - Headers: - Subject: Title

A message resource is present, but this message was not found in the message table

Do you have any idea now? What's going wrong?


Solution

  • I've got it! Now it works!

    I had to go to myaccount.google.com > security and set 2 step verification, and then generate app password (for xampp).

    I did it thanks to this video: https://www.youtube.com/watch?v=L5uCc8Hab-I

    Thanks!