是否可以在不使用任何外部类的情况下通过 gmail smtp 在核心 php 中发送邮件?
最佳答案
关于这一点有很多误解。通过 PHP 的简单“mail()”命令使用 gmail 发送电子邮件是 100% 可能的。 而且它是 100% 简单的。
安装 SSMTP:
sudo apt-get install ssmtp
编辑其设置文件:
sudo nano /etc/ssmtp/ssmtp.conf
在内部,使其与此类似,但使用您自己的凭据:
mailhub=smtp.gmail.com:587
AuthUser=youremail@gmail.com
AuthPass=password
UseSTARTTLS=YES
# You can only do this if you've verified your domain with Gmail.
# If you haven't, delete, or add a # before this
hostname=yourwebsite.com
FromLineOverride=YES
最后,打开您的 php.ini,搜索 sendmail_path 并使用此值:
sendmail_path = /usr/sbin/ssmtp -t
就是这样!使用简单的 1 行邮件功能
在您的 PHP 中对其进行测试:mail('to@address.com', 'Subject', 'Message', 'From: Your name <youremail@gmail.com>');
Gmail 安全更新
Gmail 现在默认阻止此操作。您仍然可以通过访问来执行此操作:http://www.google.com/settings/security/lesssecureapps
开启此功能。
关于php - 使用核心 php mail() 通过 gmail SMTP 发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10028428/