I made a simple webpage to send emails to an email address. I was testing it on localhost using xampp. Tried a few time and the email always failed to send. I checked the error log and found these errors:
[Mon Nov 16 18:27:54.432224 2020] [ssl:warn] [pid 14464:tid 592] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Mon Nov 16 18:27:54.450227 2020] [mpm_winnt:notice] [pid 14464:tid 592] AH00354: Child: Starting 150 worker threads.
sendmail: Error during delivery: Username and Password not accepted. Learn more at https://support.google.com/mail/?p=BadCrede
I checked my email address and password in sendmail.ini and they are correct. Also went through the information in the link. Still cannot figure it out.
My php code is here:
<?php
$headers = "";
ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","587");
if (isset($_POST['email'])){
$to = 'anthonylaw8910@gmail.com';
$subject = 'message from site';
}
$message = 'Name: '.$_POST['name']."\r\n\r\n";
$message.= 'Email: '.$_POST['email']."\r\n\r\n";
$message.= 'Message: '.$_POST['comments'];
$headers = "From: testReceive@gmail.com\r\n";
$headers.= 'Content-Type: text/plain; charset=utf-8';
$success = mail($to, $subject, $message, $headers);
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<title> send message </title>
<meta charset="UTF-8">
</head>
<body>
<?php if (isset($success) && $success) {?>
<h1>Successful</h1>
message sent
<?php } else { ?>
<h1>Failed</h1>
message not sent
<?php } ?>
</body>
</html>
For php.in:
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = testSend@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
For sendmail.in:
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=YourGmailId@gmail.com
auth_password=Your-Gmail-Password
force_sender=YourGmailId@gmail.com
You might want to configure “Less secure apps” settings as described here https://support.google.com/cloudidentity/answer/6260879..
switch between ports 587, 25 and 465
check if mails are being sent late.
Check if the port is blocked or your firewall is stopping it.
Ensure Gmail is allowing the access
Also sometimes, you just need to restart your server because you probably did new settings.
Here is a link to ensure all settings and processes are correct.
https://www.phpflow.com/php/how-to-send-email-from-localhost-using-php/