[英]XAMPP: How to send an email using Gmail SMTP in PHP?
I'm running as localhost, and I want to send an email through my gmail account to my hotmail account using google's SMTP server.我作为本地主机运行,我想使用 google 的 SMTP 服务器通过我的 gmail 帐户向我的 hotmail 帐户发送一封电子邮件。 Here are the
.ini
configurations:以下是
.ini
配置:
sendmail.ini (the entire file) sendmail.ini(整个文件)
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=myemailgmail.com
auth_password=mypassword
force_sender=myemail@gmail.com
php.ini (only the [mail function]
part): php.ini(仅
[mail function]
部分):
[mail function]
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = myemail@gmail.com
sendmail_path = "\"C:\xampp2\sendmail\sendmail.exe\" -t"
When I call mail($email, "Email verification code", "Your verification code is: " . $generated_code);
当我调用
mail($email, "Email verification code", "Your verification code is: " . $generated_code);
(where $email is some outlook.com email address) (其中 $email 是一些 Outlook.com 电子邮件地址)
I check the php error log, and there's no errors when calling this function.我查看了php错误日志,调用这个函数时没有错误。 It executes fine.
它执行得很好。 When I check my outlook email, I did not receive the email.
当我查看 Outlook 电子邮件时,我没有收到电子邮件。
What can I do to have the email sent?我该怎么做才能发送电子邮件?
My account has Two-factor authentication enabled (using Google authenticator), so I was unable to access the account using my password alone. 我的帐户启用了双因素身份验证(使用Google身份验证器),因此我无法仅使用密码访问该帐户。 So I bypassed it by going into "Google Account" -> Security -> App passwords and set up an app password for Mail.
所以我通过进入“Google帐户” - >安全性 - >应用程序密码并为Mail设置应用程序密码来绕过它。 Now I can access my Google account using the app password (without 2fa) from my computer, by setting:
现在,我可以通过设置从我的计算机使用应用密码(不含2fa)访问我的Google帐户:
auth_password=myGmailAppPassword
Then I restarted Apache and it worked. 然后我重新启动Apache,它工作正常。
I have created a form that enables to send a message to your Email... 我创建了一个表单,可以向您的电子邮件发送消息...
( https://drive.google.com/open?id=1eWdBALpoFF_LWI3obfCujQ6_jHZAwZXf ) ( https://drive.google.com/open?id=1eWdBALpoFF_LWI3obfCujQ6_jHZAwZXf )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.