How to Test Emails from Local Hosts

I don’t know what’s your level of frustration when you have to test emails from local hosts, but there is no suitable way to test it on the local sites, and you don’t want to check it on the live sites due to a lot of unknown facts, my level of frustration always remains high. I tried several methods, but none of them were satisfactory. After investing a lot of time, I finally figured out a handy and easy peasy solution to test the email setup on local hosts. In this article, I will share my learnings with you.

Required Things

To manage the work, you need only three things. 

  • WordPress on your Local Host
  • SMTP plugin
  • An account on Mailtrap

What is Mailtrap?

Local Host Email testing tool Mailtrap

Mailtrap is a fake SMTP server tool that allows you to test your local hosts’ emails decently. It grabs emails from the Local Host, Stage, QA, etc., and helps you to test, preview, and debug your HTML emails.

In my words, Mailtrap will give an email box with a dedicated email id with extensive functionality to test emails from local hosts or staging sites.

The best part is that they have a free version to test up to 50 emails in your dedicated email box. Even when your email box is full, you can remove emails and test new emails too.

Creating an Account on Mailtrap

Creating an account on Mailtrap is so easy. You can signup with your Google account/GitHub account or create a new account through your email address, a new account.

Setting Up the SMTP with WordPress Plugin And Connet with Mailtrap

I don’t take your time to go with the basics of the SMTP plugin. You can find the details of those plugins on their websites. Among all of the SMTP plugins, there are a few are supported by Mailtrap. Here are those,

  • WP Mail SMTP by WPForms
  • Easy WP SMTP
  • Post-SMTP Mailer/Email Log
  • Email Subscribers & Newsletters

Setting up Mailtrap with WP Mail SMTP by WPForms to Test Local Hosts’ Emails

WP Mail SMTP is a free plugin to set up the mail SMTP in the WordPress system. The setup process is so easy. Follow the below steps,

Step 1

Search on WordPress Repository, Install and activate it.

Or you can download the zipped file and extract it on your WP Content Folder to save your time ?

Step 2

Now navigate to the settings option of the WP SMTP.

email testing with WP SMTP Gtarafdar

Tips:
If you find the From email field filled with your admin email, please remove it and keep it blank. The WP SMTP plugin will set the default email address for you, which will help you to send emails to your Mailtrap mailbox. In my case, it causes difficulties in testing emails.

Step 3

Now select the Other SMTP option and set the below-mentioned options and, log in to your Mailtrap account & open your demo email box to get the necessary Infos.

Mailtrap Setup for testing emails from local host

Steps to follow ?

  • SMTP hostname: smtp.mailtrap.io
  • SMTP port: 25 or 465 or 587 or 2525
  • Encryption method: keep them as it is 
  • Set Username and password to authenticate: Available on Mailtrap’s Demo Inbox Set up the page.
  • Click Save Changes Button
Mailtrap Setup For Testing Emails on Local Host

Step 4

Note that in this case, your password will be stored in the website database in plain text. This is why for extra security, it is recommended to set up the password in your wp-config.php file by adding these two lines of code:

define( 'WPMS_ON', true );
define( 'WPMS_SMTP_PASS', 'your_password' );

Step 5

All setup is done. It’s time for testing. To test your whole work navigate to the Email Test tab of the WP SMTP Plugin.

Test eamil in local host

Now copy email address from the Email Address Tab of the Demo Inbox of your Mailtrap

Testing Emails from local hosts

Paste the email address to Send To email field and click send button.

local host setuup for email testing

Hola, your test email is in your mailbox…

Good News:

Mailtrap collects all emails from your local host and will display them in your Miltrap’s Inbox. So you can use any kind of email address to test.

How to Configure Mail SMTP Without Any Plugins

If you are a tech nerd and don’t want to bloat your database with unnecessary plugins, then here is a code snippet. Jump into your functions.php file and configure the WordPress SMTP settings with the following code:

add_action( 'phpmailer_init', 'setup_phpmailer_init' );
function setup_phpmailer_init( PHPMailer $phpmailer ) {
    $phpmailer->Host = 'HOSTNAME'; // for example, smtp.mailtrap.io
    $phpmailer->Port = 587; // set the appropriate port: 465, 2525, etc.
    $phpmailer->Username = 'YOURUSERNAME'; // your SMTP username
    $phpmailer->Password = 'YOURPASSWORD'; // your SMTP password
    $phpmailer->SMTPAuth = true; 
    $phpmailer->SMTPSecure = 'tls'; // preferable but optional
    $phpmailer->IsSMTP();

The interesting fact is that Mailtrap has Already created a readymade snippet for you. Go to the Demo inbox of your Mailtrap Account, and from the integration Dropdown menu, select WordPress and copy code, and finally paste it on functions.php file and save it.

configure smtp for testing local emails

Bonus Tips

Special Care for Lazy Bees like me ?

If you don’t want to do all that to test an email body, it is only interesting to know the system status, whether it is functional or not. Then, you can check this free tool. This plugin will help you to track the state of the emails. It will help you understand whether the email is shot from your environment or not.

Video Tutorial on How to Test Emails from Localhosts

If you are interested in watching the tutorial video of the whole process, then jump into it.

YouTube video

Ending Thoughts

I have tried to cover all the areas to make a foolproof guideline on how to test your emails in your local host setup. Please let me know in the comment section if you find any other suitable and easy solution. I’ll add it to the next update of my content.

Leave a Reply

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

0 Shares
Share via
Copy link
Powered by Social Snap