为什么我发送邮件时遇到服务器证书错误和密码未被接受的错误?
Why I encounter server certificate error and password not aceepted error sending an email?
我做了一个简单的网页来发送电子邮件到一个电子邮件地址。我正在本地主机上使用 xampp 对其进行测试。试了几次,邮件总是发不出去。我检查了错误日志并发现了这些错误:
[11 月 16 日星期一 18:27:54.432224 2020] [ssl:warn] [pid 14464:tid 592] AH01909:www.example.com:443:0 服务器证书不包含与服务器匹配的 ID名字
[11 月 16 日星期一 18:27:54.450227 2020] [mpm_winnt:通知] [pid 14464:tid 592] AH00354:Child:启动 150 个工作线程。
sendmail:投递时出错:不接受用户名和密码。了解更多信息
https://support.google.com/mail/?p=BadCrede
我在 sendmail.ini 中检查了我的电子邮件地址和密码,它们是正确的。也翻阅了link中的资料。还是想不通。
我的 php 代码在这里:
<?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>
对于php.in:
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = testSend@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
对于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
您可能需要按照此处所述配置“安全性较低的应用”设置 https://support.google.com/cloudidentity/answer/6260879.。
在端口 587、25 和 465 之间切换
检查邮件是否延迟发送。
检查端口是否被阻止或您的防火墙正在阻止它。
确保 Gmail 允许访问
此外,有时您可能只需要重新启动服务器,因为您可能进行了新设置。
这里有一个link来确保所有的设置和流程都是正确的。
https://www.phpflow.com/php/how-to-send-email-from-localhost-using-php/
我做了一个简单的网页来发送电子邮件到一个电子邮件地址。我正在本地主机上使用 xampp 对其进行测试。试了几次,邮件总是发不出去。我检查了错误日志并发现了这些错误:
[11 月 16 日星期一 18:27:54.432224 2020] [ssl:warn] [pid 14464:tid 592] AH01909:www.example.com:443:0 服务器证书不包含与服务器匹配的 ID名字
[11 月 16 日星期一 18:27:54.450227 2020] [mpm_winnt:通知] [pid 14464:tid 592] AH00354:Child:启动 150 个工作线程。
sendmail:投递时出错:不接受用户名和密码。了解更多信息 https://support.google.com/mail/?p=BadCrede
我在 sendmail.ini 中检查了我的电子邮件地址和密码,它们是正确的。也翻阅了link中的资料。还是想不通。
我的 php 代码在这里:
<?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>
对于php.in:
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = testSend@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
对于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
您可能需要按照此处所述配置“安全性较低的应用”设置 https://support.google.com/cloudidentity/answer/6260879.。
在端口 587、25 和 465 之间切换
检查邮件是否延迟发送。
检查端口是否被阻止或您的防火墙正在阻止它。
确保 Gmail 允许访问
此外,有时您可能只需要重新启动服务器,因为您可能进行了新设置。
这里有一个link来确保所有的设置和流程都是正确的。
https://www.phpflow.com/php/how-to-send-email-from-localhost-using-php/