Contact Form 7 Cannot Send Emails from DigitalOcean Server

By | April 3, 2016

“Failed to send your message. Please try later or contact the administrator by another method.”

Are you seeing the above error when trying to send a message via the Contact Form 7 plugin for WordPress?

The Contact Form 7 plugin sends email using a mail server installed on your DigitalOcean server. If no mail server is installed, then your visitors will see the above error whenever they try to submit a message via the form.

This post will walk you through the steps required to setup the lightweight email server msmtp on your Digital Ocean server, so that WordPress plugins like Contact Form 7 can send email messages.

INSTALL MSMTP

SSH into your server.

First, use the package manager to check if msmtp is already installed:

If it’s not, then issue the following command to install it:

CONFIGURE MSMTP

Use the version option to find out where msmtp’s configuration file is located:

Display the contents of the configuration file:

If a configuration file doesn’t exist, create one using the vi program:

Replace the contents of the configuration file with the text below, substituting “username@gmail.com” and “yourpassword” with your own Gmail address and password:

CONFIGURE PHP

You need to tell PHP, via its configuration file, that you want to use msmtp as your mail server.

First, make a backup copy of the php.ini file before making any changes to it:

Edit php.ini using vi:

Find the “sendmail_path” parameter. You can easily find it by pressing the forward slash key ‘/’, typing “sendmail_path” and hitting the enter key.

Uncomment the line by deleting the semicolon and add the following:

Save the file. In vi, you can save the file by pressing the ‘ESC’ key, typing “wq” and hitting enter.

YOU’RE DONE

You should now be able to submit emails via the Contact 7 Form. If you’re still getting error messages, follow the troubleshooting section below.

How did it go? Are you still having problems? Leave a comment below!

TROUBLESHOOTING

The Apache error log can offer insight into what’s causing the problem:

Look for any msmtp error messages in the output.

AUTHENTICATION FAILURE

If you have dual factor authentication enabled for your Gmail account, you will likely see this error in the Apache log:

To resolve this, you must create an Gmail app password for the msmtp application, which basically involves logging into your gmail account and creating a password for this specific application.

Follow the link in the error message for more detailed information. Here is an outline of the steps to follow:

  1. Follow this link to access the Gmail app passwords page
  2. Sign in with your Gmail ID and password
  3. Click the “Select app” dropdown box
  4. Select “Other (custom name)”
  5. Type “msmtp” (or any name that you prefer) into the text box
  6. Click the “Generate” button
  7. Copy and paste the generated app password into the msmtp configuration file, replacing your gmail password
  8. Save the configuration file
  9. Try sending another message using the Contact 7 Form

 

Leave a Reply

Your email address will not be published.

*