Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

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

ubuntu - How do I specify to PHP that mail() should be sent using an external mail server?

I have my email hosted at Rackspace Email and would like to use that as my mail server for the contact form on my website.

Looking at the php.ini file, I'm only able to specify the sendmail_path on UNIX systems, from which I've read points to the program that actually sends mail on the server.

I do not want to send mail from my Ubuntu server since I'm not experienced enough to make a secure setup for email... I would like to relay everything to Rackspace's mail.emailsrvr.com.

My question is, how do I specify to the PHP setup on my server that the mail() function should be using an external mail server?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Since I was researching this issue and stumbled across this post and a third-party php library was not an option for me.

As we know, php uses the sendmail command of the server by default The sendmail_path option in php.ini can be changed to override the setting to your own command with it's own arguments, etc. For example: sendmail_path = /usr/bin/unix2dos | /usr/bin/dos2unix | /usr/sbin/sendmail -t -i

SSMTP will allow you to direct outbound emails to a mailhost from your web/php server. https://wiki.archlinux.org/index.php/SSMTP

apt-get install ssmtp

Then you can use sendmail_path = /usr/sbin/ssmtp -t to tell php to use ssmtp instead of sendmail. Be sure to restart your web server after you have made changes to php.ini

Also ensure you have configured ssmtp and validated your SPF, DKIM, DMARC records before you make the changes to sendmail_path in php.ini

For example gmail Mail server. /etc/ssmtp/ssmtp.conf

# The user that gets all the mails (UID < 1000, usually the admin)
[email protected]

# The mail server (where the mail is sent to), both port 465 or 587 should be acceptable
# See also http://mail.google.com/support/bin/answer.py?answer=78799
mailhub=smtp.gmail.com:587

# The address where the mail appears to come from for user authentication.
rewriteDomain=yourdomain.com

# The full hostname
hostname=FQDN.yourdomain.com

# Use SSL/TLS before starting negotiation
UseTLS=Yes
UseSTARTTLS=Yes

# Username/Password
[email protected]
AuthPass=postmaster-password

# Email 'From header's can override the default domain?
FromLineOverride=yes

For a stack exchange question to the same see https://unix.stackexchange.com/questions/36982/can-i-set-up-system-mail-to-use-an-external-smtp-server

To expand on this.

If using Google, each From: email address must be setup on the sending account as an "Account You Own" setting under accounts. Otherwise google will rewrite the headers with x-google-original-from and specify the From as the sending account instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...