Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

using core php mail() to send via gmail SMTP

Is it possible to send mail in core php via gmail smtp without using any external class?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There's a lot of miscommunication about this. It is 100% possible to send emails using gmail via PHP's simple "mail()" command. And it is 100% easy.

Install SSMTP:

sudo apt-get install ssmtp

Edit its settings file:

sudo nano /etc/ssmtp/ssmtp.conf

Inside, make it similar to this, but with your own credentials:

mailhub=smtp.gmail.com:587
[email protected]
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

Lastly, open your php.ini, and search for sendmail_path and use this value:

sendmail_path = /usr/sbin/ssmtp -t

That's it! Test it out in your PHP, with the simple 1-line mail function:

mail('[email protected]', 'Subject', 'Message', 'From: Your name <[email protected]>');

Update on Gmail Security

Gmail now blocks this by default. You can still do this by visiting: http://www.google.com/settings/security/lesssecureapps

Turn this feature ON.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...