Configure Your Web Server To Send Email

send emails from a web server

Whether you’re using a contact form with WordPress or operating your own e-commerce shopping cart, the ability to send emails from a web server is a critical component of running an online business. But due to headaches with spam filters and the need for tight security, it isn’t feasible for most online businesses to run their own email servers.

This is where email services like Fastmail or MailChimp come in. By sending emails through their trusted servers, you have far fewer headaches. Configuring access is nearly as easy as setting up an account in an email app.

Considerations

If you’d like to add a contact form to your website, you should consider the amount of volume you expect to receive each day. You’re safe to use a regular email service like Fastmail if you receive a dozen or less emails a day from your website.

However, if you expect a higher volume of emails you should use a dedicated email-sending service like MailChimp. They specialize in sending high-volume business emails to make sure yours are effective and don’t end up in the Spam folder.

Plugin or Server Admin?

Sendmail (SMTP) plugins like Postman SMTP for use with WooCommerce or simple contact plugins like Pirate Forms that have their own ability to set up a SMTP connection can allow you to set up connection quickly. These make good choices if you aren’t able to make changes to your web server.

However, setting up access to your email service’s SMTP server for PHP on your web server will give all the PHP scripts you run access to sending email, and is relatively easy to accomplish when you access your server directly using the Terminal on Mac or Linux or PuTTY on Windows.

This method is also more secure than using a WordPress plugin. Your email account password will be stored in a secure folder on the server rather than in your site’s WordPress database when you send emails from a web server.

As an online entrepreneur it makes sense to leave this type of work to your freelance web developer. However, understanding some of the specifics when you send emails from a web server will allow you to work more closely with your freelance web developer to make the best choices for your site.

How To Set Up MSMTP

These steps assume you are using a Linux web server running either Debian, Ubuntu or one of their variants. If you’re using a version of Linux like CentOS, RedHat or others, the steps will be very similar but may not match up.

You can copy and paste the quoted lines, but make sure that you’re following good security practices and using a regular user account set up with sudo.

1. Download MSMTP

MSMTP is a simple program that connects to your email account’s SMTP server.

sudo apt-get update && sudo apt-get upgrade

sudo apt-get install msmtp

2. Configure MSMTP

Configuration is about as easy as configuring a WordPress plugin, except we’ll be entering the server information in a plain text file rather than a web form. Note that these settings will vary depending on your email provider, so check your providers SMTP settings to make sure you’re entering the correct information.

sudo nano /etc/.msmtp_php

This will show a blank file. Enter your SMTP information according to the format below. I’ve used Fastmail in the illustration, but you should edit the entries to match your own information.

account  Fastmail
auth  on
tls_starttls  off
tls  on
tls_certcheck  off
from ****@fastmail.com
user ****@fastmail.com
password **************
logfile /var/log/msmtp.log

Save that file and create your log file. Afterward, change the ownership of the two files to match your web server’s account. Note that “www-data” may be something different if you’re not using Debian.

sudo touch /var/log/msmtp.log

sudo chown www-data:www-data /etc/.msmtp_php

sudo chown www-data:www-data /var/log/msmtp.log

3. Add MSMTP to PHP

Finally, you need to add the path to MSMTP in your server’s PHP configuration file. Once again, some of the information here may not be the same on your web server’s system. Your php.ini file may be located in a different place under the /etc/php5 folder, for instance.

sudo nano /etc/php5/cgi/php.ini

This file will already be full of information that PHP uses to run on your web server. Search for “sendmail_path =” in the file. If it has a “#” in front, remove that and change it to:

sendmail_path = “/usr/bin/msmtp -C /etc/.msmtp_php -a Fastmail -t”

Note again that the path to MSMTP may be different on your system, though the path above should be typical for a Debian system.

Restart your web server and it should be working now.

sudo /etc/init.d/lighttpd restart

or

sudo /etc/init.d/apache2 restart

Or perhaps even another name depending on what web server you use and your version of Linux.

4. All Done

Assuming all the steps were performed correctly for your system and your email account’s information was entered correctly, you should be able to send emails from a web server through PHP (and WordPress) now.

Not so bad was it? Even if you’re still not sure about how to send emails from your web server, understanding some of what goes on will help you when it comes time to choose a freelance web developer to work on your website.


Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *