Welcome to 20i Support

Web Hosting Knowledge Base

WordPress knowledge: use SMTP with and without plugins

Sending emails directly from your WordPress site can be critical to your site’s success. It could be from a contact form to help your clients get in touch if they’re interested in your services, order emails to confirm details and provide receipts for purchases, or password reset emails to allow users access to their accounts.

WordPress itself comes with functionality out of the box that can allow for sending emails, but it’s not as secure as it could be, and can more often than not result in your business-critical emails resulting in the Spam folder.

Making use of SMTP with your WordPress site, however, can ensure that all of these important emails make it to their intended audience. Setting them up is much easier than you’d think. This guide will step you through what SMTP is, why it’s important to make use of it on your WordPress sites, and explain a couple of ways for you to get started using SMTP as soon as possible.

What is SMTP?

SMTP, also known as the Simple Mail Transfer Protocol, is the main protocol used to send and receive email. A majority of email systems make use of SMTP to send out emails between servers. These emails can then be retrieved using email client protocols such as IMAP  or POP3.

Why should I use SMTP with WordPress?

By default, WordPress makes use of PHP Mail using the wp_mail function to send emails from contact forms, product orders and other functions that send out automated emails. However, PHP Mail lacks any form of authentication – it simply sends with the from address it’s provided directly from the server itself.

As a result, PHP Mail often gets used to spoof email addresses, commonly enough that some mail hosts simply mark emails from PHP Mail as spam or may even get blocked.

SMTP, on the other hand, connects to a mailbox directly and authenticates the connection using the mailbox password before it sends. This means that only setups with the correct mailbox details can actually send out emails. This is considered much more secure and can ensure that your site’s emails are less likely to be seen as spam and make their way to your intended recipients.

How can I connect using SMTP?

Connecting your WordPress site to your mailboxes using SMTP first requires you to understand where your emails are hosted – each mail host has a different hostname for their SMTP services. Knowing what this is can save you a headache in the long run. Some services have setups available to allow you to use smtp.yourdomain.com to connect, but this requires that subdomain on your domain to be pointed to their services.

If your emails are hosted here with us at 20i, our SMTP settings are as follows:

Hostname: smtp.stackmail.com

Port: 465 (SSL) or 587 (TLS)

Security: SSL/TLS

Username: Your email address you want to send with

Password: The password of the mailbox you want to send with

 

If you use Office365 to host your mailboxes instead, you’ll need to use their SMTP details:

Hostname: smtp.office365.com

Port: 587

Security: STARTTLS

Username: Your email address you want to send with

Password: The password of the mailbox you want to send with

 

Other mail hosts will provide guidelines or quick references online that will specify the SMTP connection details you need. If you’re unsure, check with them directly to confirm.

Once you have the details you need, it’s time to connect. Doing so can be done a couple of ways, depending on how confident you are with coding.

Connecting to SMTP using a Plugin

If you’re unsure and want an easy way to do it, there are a great number of WordPress plugins that handle the heavy workload of the connection for you, allowing you to simply pop in your SMTP details and begin sending straight away. We'll demonstrate the setup SMTP in WordPress with a plugin using two examples of popular ones. These are:

WP Mail SMTP

WP Mail SMTP is a free plugin that comes with a wizard that runs automatically upon installation and steps you through setting up your SMTP connection. When you first install it, you’ll be prevented with the following screen:

WP Mail SMTP WordPress plugin

Select Let’s Get Started and you’ll be presented with some options for what type of SMTP service you use – there’s various auto configurations for different hosts, such as Google, Office365, Mailgun and SendGrid. If you use 20i’s mail services, you’ll want to select Other SMTP. If you’re unsure, check with your current mail host.

WP Mail SMTP WordPress plugin choose email client

On the next page, you’ll be presented a form – follow the steps here to fill out your details. SMTP Host is where you’d input your hostname, and Encryption is your security – we recommend SSL or TLS, depending on what host you use.

WP Mail SMTP WordPress plugin configuration

Make sure that Authentication is enabled, then input your SMTP Username and SMTP Password – these are the email and the mailbox password respectively. Lastly, set a From Name, which is the name that will appear as the sender of the email, and the From Email. You’ll want to make sure the From Email matches the SMTP username.

WP Mail SMTP WordPress plugin authentication

WP Mail SMTP will then prompt you with some additional preferences – you can choose to enable these based on what you’d like of the plugin. If you’re unsure, leave it as default.

WP Mail SMTP WordPress plugin features

WP Mail SMTP will then run a quick test of the settings you’ve used – if there’s any errors, you’ll then be prompted to recheck your details.

If not, you’ll see the following screen:

WP Mail SMTP WordPress plugin success notification

And you’re all set to send your emails using SMTP.

Easy WP SMTP

Easy WP SMTP aims to make setting SMTP up and testing as quick and as simple as possible. Once it’s installed, head to the Settings tab of your WP Admin area, and you should see a new option for Easy WP SMTP.

Easy WP SMTP plugin in settings

Once selected, you’ll be greeted with a form with all of your needed details. From Email Address is the email address you wish to use for sending, and your From Name is the name you want the email to appear to come from. Reply-To Address is the address used for the Reply-To field, and you can also set a BCC Email Address if you want to have a copy of the email sent to another mailbox.

Easy WP SMTP plugin in settings account

Below that, you have entry fields for your SMTP Host, which is your email provider’s SMTP hostname, the Encryption, which is the security, and your SMTP Port. Set these to your mail provider’s required settings, and select Yes on SMTP Authentication.

Lastly, enter the mailbox you wish to send from into SMTP Username and the mailbox’s password in SMTP Password, and hit Save Changes.

Easy WP SMTP plugin in settings username and password

You can then navigate to the Test Email tab at the top of the form, and send a test email to check the SMTP settings are configured correctly.

If everything is configured correctly, you’ll get a popup confirming your email went through, and you’ll be all set to begin sending emails from your WordPress site using SMTP.

Easy WP SMTP plugin test email

Without Plugins

If you’re more confident with PHP coding and the inner workings of WordPress, you can also set up your SMTP details directly using code. To do this, you’ll need to have set up a WordPress child theme – WordPress themselves provide a guide on how to do so here [ https://developer.wordpress.org/themes/advanced-topics/child-themes/ ]

Note: Before attempting this, make a backup of your site files so that you have a restore point.

In order to do so, first head to your wp-config.php file in the core folder of your WordPress site and add the following code:

// Configure your site to use SMTP

    define( 'SMTP_USER',   'email@example.com' );    // Username to use for SMTP authentication

    define( 'SMTP_PASS',   'MAIL_PASSWORD' );       // Password to use for SMTP authentication

    define( 'SMTP_HOST',   'smtp.stackmail.com' );    // The hostname of the mail server

    define( 'SMTP_FROM',   'email@example.com' ); // SMTP From email address

    define( 'SMTP_NAME',   'FROM_NAME' );    // SMTP From name

    define( 'SMTP_PORT',   '587' );                  // SMTP port number - likely to be 25, 465 or 587

    define( 'SMTP_SECURE', 'tls' );                 // Encryption system to use - ssl or tls

    define( 'SMTP_AUTH',    true );                 // Use SMTP authentication (true|false)

    define( 'SMTP_DEBUG',   0 );                    // for debugging purposes only set to 1 or 2

This sets up the base configurations for your SMTP setup – you’ll want to modify the values above to match the recommended settings provided by your email host, and your own personal preferences.

Then, head to your child theme folder in wp-content > themes and open functions.php. In this file, add the following code:

    // Configures SMTP authentication for your site

    add_action( 'phpmailer_init', 'send_smtp_email' );

    function send_smtp_email( $phpmailer ) {

        $phpmailer->isSMTP();

        $phpmailer->Host       = SMTP_HOST;

        $phpmailer->SMTPAuth   = SMTP_AUTH;

        $phpmailer->Port       = SMTP_PORT;

        $phpmailer->Username   = SMTP_USER;

        $phpmailer->Password   = SMTP_PASS;

        $phpmailer->SMTPSecure = SMTP_SECURE;

        $phpmailer->From       = SMTP_FROM;

        $phpmailer->FromName   = SMTP_NAME;

    }

And that’s it – your site should now be able to use SMTP for sending your emails directly from your website.

Setting up SMTP with the above steps can ensure that your sent emails are safe, and better improve your chances of having them arrive with your clients without being flagged as spam and potentially missed.