【发布时间】:2019-12-20 21:34:17
【问题描述】:
我想使用 PHP 和 Xampp 从 localhost 发送 Gmail 邮件。我尝试通过 Youtube 看教程。但即使我一步一步地遵循它仍然无法正常工作。我的PHP代码如下:
<?php
mail('mypersonalemail@gmail.com','Testing send email using PHP','Content
here','From: otheremail@gmail.com');
?>
我还在“php.ini”文件和“sendmail.ini”中做了一些Xampp配置,如下所示:
1) php.ini:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP=smtp.gmail.com
; http://php.net/smtp-port
smtp_port=587
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = mypersonalemail@gmail.com
sendmail_path = "\"D:\xampp\sendmail\sendmail.exe\" -t"
2) 发送邮件.ini:
smtp_server=smtp.gmail.com
smtp_port=587
auth_username=mypersonalemail@gmail.com
auth_password=mygmailpassword
而我的PHP文件的文件位置是C:\xampp\htdocs\testemail.php
我使用http://localhost/testemail.php 运行本地主机。我也尝试将端口号更改为 25、587 和 465。如果我遗漏了什么,请指导我。
【问题讨论】:
-
您确定不对您的 gmail 帐户进行任何更改吗?也许是关于安全?
-
我已经更改了 gmail 帐户设置
-
请使用php邮件库
-
mail函数不是此任务的正确工具。像 phpmailer 和 Zend\Mail 这样的邮件程序支持通过 SSL/TLS 发送邮件。 -
你能试试that answer的所有步骤吗?