从本地主机发送电子邮件,而无需使用 GMAIL 邮件服务器在 PHP 中运行 XAMMP


Send email from localhost without running XAMMP in PHP using GMAIL mail server

我没有使用 xammp,而是使用"假 sendmail for windows"。

使用此"发送邮件.ini设置

'[Modify] the php.ini file to use it (commented out the other lines):
'[mail function]
'; For Win32 only.
'; SMTP = smtp.gmail.com
'; smtp_port = 25
'; For Win32 only.
'; sendmail_from = <e-mail username>@gmail.com
'; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
'sendmail_path = "C:'xampp'sendmail'sendmail.exe -t"

以及PHP的此设置.ini

[sendmail]
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=<username>
auth_password=<password>
force_sender=<e-mail username>@gmail.com'

但我仍然反对这个错误

'Warning: mail(): SMTP server response: 421-4.7.0 [14.200.59.18 15] Our      system has detected that this message is 421-4.7.0 suspicious due to the very low reputation of the sending IP address. 421-4.7.0 To protect our users from spam, mail sent from your IP address has 421-4.7.0 been temporarily rate limited. Please visit 421 4.7.0 https://support.google.com/mail/answer/188131 for more information. c185si2211020itg.117 - gsmtp in C:'Program Files (x86)'EasyPHP-Devserver-16.1'eds-www'introducingphp'Code Work php'testmail.php on line 10
Check your email now....'

我的测试邮件.php代码是:

<?php
ini_set("SMTP", "aspmx.l.google.com");
ini_set("sendmail_from", "my_email@gmail.com");
$message = "The mail message was sent with the following mail     setting:'r'nSMTP = aspmx.l.google.com'r'nsmtp_port = 25'r'nsendmail_from = my_email@gmail.com";
$headers = "From:my_email@gmail.com";

mail("to_email@yahoo.com", "Testing", $message, $headers);
echo "Check your email now....<BR/>";
?>

这是电子邮件如此容易发送的不幸副作用 - 任何人都可以按照您的方式编写代码并开始发送电子邮件。虽然你的意图很可能是纯粹的,但有什么能阻止你在循环中运行你的代码,向字母和数字的每个组合发送成千上万的消息,以@gmail.com 结尾?

垃圾邮件过滤器,就是这样。https://support.google.com/mail/answer/188131,根据错误消息提供的链接,很明显,Google认为您的服务器(实际上只是一个桌面,我假设在个人互联网连接上)不符合他们的准则(https://support.google.com/mail/answer/81126?hl=en)。您当然可以在家中设置静态IP之类的东西,以尝试提高IP地址的声誉,并遵循所有Google指南...但是使用网络托管公司的服务器来运行您的代码可能要容易得多。

另一种选择是干脆不将电子邮件发送到Gmail - 如果您已经在虚拟主机上设置了域名,则可能发送到限制较少的邮件服务器。这样,您可以确定您将收到消息。