简体   繁体   English

PHP mail()-无法从本地主机(xampp)向Gmail发送邮件

[英]PHP mail()- can't send mails to Gmail from localhost(xampp)

For a school project I need to send e-mails from localhost to gmail. 对于学校项目,我需要从本地主机向gmail发送电子邮件。 I have downloaded and copied all of the files from http://glob.com.au/sendmail/ and pasted them into my xampp/sendmail folder. 我已经从http://glob.com.au/sendmail/下载并复制了所有文件,并将它们粘贴到我的xampp / sendmail文件夹中。

Here are my settings which should technically work. 这是我的设置,在技术上应该可以使用。

sendmail.ini: sendmail.ini:

smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=auto
auth_username=myemail@gmail.com
auth_password=mypassword

php.ini: php.ini:

sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"
; SMTP = localhost
; smtp_port = 25

If you are using xampp you can check this answer: [ How to configure XAMPP to send mail from localhost? 如果使用的是xampp,则可以检查以下答案:[ 如何配置XAMPP从本地主机发送邮件?

Or you can use phpmailler instead of this method. 或者您可以使用phpmailler代替此方法。

  1. Make sure you run sendmail.exe as an Administrator and in Compatibility Mode 'Windows XP (Service Pack 3)'. 确保以管理员身份和兼容模式“ Windows XP(Service Pack 3)”运行sendmail.exe。 Right-click -> Properties -> Compatibility. 右键单击->属性->兼容性。
  2. Then visit the following link https://www.google.com/settings/security/lesssecureapps and Accept. 然后访问以下链接https://www.google.com/settings/security/lesssecureapps并接受。 Otherwise Gmail will block incoming requests. 否则,Gmail将阻止传入的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM