When you self-host WordPress, getting a contact form running can be one of the more confusing tasks. The contact form in your theme usually isn't the problem - it's configuring the outbound mail server. I highly discourage people from running a mail server on their own. There are many reasons not to do so, especially performance and security. Luckily, there's an easy solution - the free Mailgun Plugin for WordPress.
Using the Mailgun Plugin for WordPress provides a simple, free solution for avoiding the challenges of running your own mail server or overcoming the limitations of your host's mail server. It makes getting contact forms up and running a lot easier.
Note: Mailgun charges based on email volume, but it's free up to many thousands of emails per month - quite sufficient for most WordPress contact forms.
Installing the Mailgun Plugin
From your WordPress Dashboard, visit Plugins -> Add New. Search for the "Mailgun for WordPress" plugin and install it.
In a moment, we'll describe the process of signing up at Mailgun so that you can provide a domain name and API key to the Plugin settings page shown below:
Sign Up with Mailgun
Visit the Visit the Mailgun website:
Sign up for the service:
While you won't need to understand any of this, Mailgun will present you with examples of how to send email with their service using cURL, Ruby, Python, PHP et al. You can use this to test the Mailgun service from your web service if you wish.
You do not need to add a domain to use Mailgun with WordPress. Messages that come from your Contact form will be delivered to you from an email address such as sandbox2732dxxxxxxxyyyyyyyyzzzzzzz49.mailgun.org. Your website visitors will not see this address. When you reply from your mail client, it should come from your primary mail address.
Return to the WordPress Dashboard, Mailgun Plugin Settings page and provide your test domain and API key given to you from the Mailgun Control Panel:
Any theme or contact form plugin that uses the standard WordPress email APIs (e.g. wp_mail) should automatically send from Mailgun. Try it out with your WordPress contact form - most times it will work seamlessly right away.
Adding Your Own Domain to Mailgun
While entirely optional, if you'd like to configure your own domain, you'll need to Add a Domain from the Mailgun Control Panel:
Mailgun will then require that you make DNS changes wherever you have your domain name registered. You'll need to create text records for your domain as shown below:
The root hostname TXT record can be configured with the @ sign e.g. @ TXT => v=spf1 include:mailgun.org ~all. The other TXT record is configured like k1._domainkey.yourdomain.com TXT => k=rsa;......long string here...
Note: Some domain name registrars have trouble with the long strings and special characters required for this. In the past I've had great trouble with MyDomain.com. I now use NameCheap.com and have had no problems.
Other Uses for Mailgun
I'm a huge enthusiast of Mailgun. It can be used for many purposes once you configure your own domain name. For example:
- Use Mailgun's secure SMTP servers to send all your outbound email.
- Configure MX records for your domain so that Mailgun's spam filters pre-screen all of your email.
- Use Mailgun's email list API as I've described in this open source tutorial. This can be used as a replacement for PHP List, MailChimp or other marketing service.
- Use Mailgun's API to programmatically send e-mail for your application.
- Use Mailgun as part of a filtering, organizing and digest solution for your email.
I hope you've found this helpful to demystifying contact forms in WordPress.
Subscribe below and we’ll send you a weekly email summary of all new Code tutorials. Never miss out on learning about the next big thing.Update me weekly