How to Configure WordPress SMTP Settings 

On January 26, 2024
8min read
Diana Lepilkina Content Specialist @Mailtrap
This is a cover image for an article that explains How to Configure WordPress SMTP Settings

Whether you run a simple WordPress website or a large WooCommerce store, you’ll need reliable email-sending functionality. And when it comes to sending emails, WordPress has multiple limitations. 

To ensure your transactional emails are sent and delivered successfully, you’ll need to set up WordPress SMTP settings properly. In this tutorial, we’ll teach you how to do that and list the various options. And make sure to create and setup an email account for your WordPress website before we proceed.

Why do you need to set up SMTP in WordPress? 

WordPress uses the PHP mail function to send emails, which isn’t the best option for several reasons. 

First, the capabilities of the default email configuration are pretty limited – you can’t easily build HTML templates, embed images, or add attachments. 

Second, PHP mail() lacks proper email headers. That’s why some web hosts deactivate WordPress mail settings. As a result, email delivery gets impeded, and such emails land in spam folders, lowering the domain reputation. 

To improve email deliverability, it is recommended to send emails using a Simple Mail Transfer Protocol (SMTP). Unlike the PHP mail() function, the SMTP server requires a header authentication and supports security mechanisms such as SSL and TLS. 

Some WordPress hosts may have an SMTP server already pre-configured for each website – but this is more of a rare exception than a trend among hosting providers. To ensure reliable email delivery from your website, it’s often recommended to work with a specialized web design company that understands the intricacies of email configuration.

For that reason, you have to set up SMTP manually. You have two main options for this: 

  • Use the PHPMailer library; 
  • Create an SMTP connection with the help of a WordPress plugin. 

Setting up WordPress SMTP with PHPMailer

To send email programmatically from WordPress using SMTP, you’ll need the PHPMailer library and some coding. 

The first step is to install the composer according to these instructions. In the root directory of your WordPress installation, create a composer.json file. Add the following code to the composer.json file to require the PHPMailer library: 

"phpmailer/phpmailer": "6.9.1"

Then, the following script will configure PHPMailer settings to use SMTP server to send HTML emails with attachments from localhost. 

<?php
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
    $mail->isSMTP();                                            //Send using SMTP
    $mail->Host       = 'YOUR_Mailtrap_Host';                   //Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
    $mail->Username   = 'api';                                 //SMTP username
    $mail->Password   = 'YOUR_Mailtrap_Password';              //SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         //Enable implicit TLS encryption
    $mail->Port       = 587;                                    //TCP port to connect to; use 587 because Mailtrap has `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

    //Recipients
    $mail->setFrom('from@example.com', 'Mailer');
    $mail->addAddress('joe@example.net', 'Joe User');     //Add a recipient
    $mail->addAddress('ellen@example.com');               //Name is optional
    $mail->addReplyTo('info@example.com', 'Information');
    $mail->addCC('cc@example.com');
    $mail->addBCC('bcc@example.com');

    //Attachments
    $mail->addAttachment('/var/tmp/file.tar.gz');         //Add attachments
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    //Optional name

    //Content
    $mail->isHTML(true);                                  //Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

How to set up WordPress SMTP email settings with WP Mail SMTP plugin

It’s possible to set up WordPress SMTP without PHPMailer. In that case, we’d need to install an SMTP plugin. 

Multiple options are available on the market, but the most popular of them is WP Mail SMTP by WPForms. It has free and paid versions that allow you to integrate your preferred SMTP provider or choose one of the built-in email service providers. 

The difference between WP Mail SMTP and PHP mail function is the fact that PHP mail() uses a local mail server, while the plugin is used to configure PHP mail to utilize an SMTP server. 

There are three ways of connecting WP Mail SMTP with your WordPress website: 

  • White glove setup offered by the plugin’s Elite version; 
  • Integration using a third-party SMTP server;
  • Integration using third-party API.

White Glove Setup 

WP Mail SMTP offers White Glove Setup service to their Elite users. You’ll choose the preferred mailer, From Name and From Address, and give them the credentials of your site. They will configure the plugin settings for you, test the setup, and contact you when everything’s ready. 

To request White Glove Setup, log into your WP Mail SMTP account and find the ‘Downloads’ tab. There, you’ll find ‘Apply for White Glove Set Up’ under your Elite license details. 

WP Mail SMTP - Apply for white glove setup
Source: WP Mail SMTP

A form will pop up to gather the necessary information, such as your website credentials, preferred mailer, DNS access for your hosting provider, etc. 

WP Mail SMTP white glove setup application form
Source: WP Mail SMTP

More information on White Glove Setup is available here

Integration using Mailtrap SMTP server

Though the previous option sounds simple, it has its limitations. It only allows you to choose between recommended mailers: SendLayer, Sendinblue, and SMTP.com. If you want to set up a custom SMTP server or integrate a third-party email provider, you’ll have to go through the manual setup. 

In this section, we’ll focus on integrating a custom SMTP server. This could be a free SMTP server or an SMTP service such as Mailtrap Email Sending. It’s an email infrastructure that delivers emails to the recipients’ inboxes just in time. 

Try Mailtrap Email Sending Now

With Email Sending, you can monitor deliverability with deliverability alerts. Weekly reports are delivered every Monday to provide a quick look into vital email statistics. If unexpected sending issues occur, critical alerts will notify you immediately. Then you can access actionable analytics for easy and fast troubleshooting. Email Sending has both solutions: API and SMTP service. 

To connect Email Sending with your WordPress site, eCommerce store, or Contact Form 7,  you first need to create an account and verify your domain with SPF, DKIM, and DMARC authentication protocols (step-by-step instructions are available here).

Once your domain is verified, choose the ‘Sending Domains’ menu, select the verified domain, and go to the ‘SMTP/API Settings’ tab. Choose Transactional or Bulk Stream depending on the type of emails you’d like to send and SMTP and save the corresponding credentials.

Now return to your WordPress dashboard and find the ‘Plugins’ section. Press ‘Add New’ and type ‘WP Mail SMTP’ in the search box. Install the plugin and activate it and head directly to the settings page. 

Installing WP Mail SMTP plugin in WordPress

Under the ‘General’ tab, the first section is ‘License’ which allows you to connect your paid account be it a Pro version, Elite, or another tier. Just paste the license key and press ‘Connect’. If you’re using a free version, you can skip this step. 

Then you have to indicate From name and From Email. Here, you should enter the name you want to be displayed on your emails and the email address that will be used for outgoing emails. This would be the email with the verified domain from the previous portion of the tutorial. 

Note: Depending on the provider, this step may be grayed out at this point. If so, integrate the mailer below and come back to this step later. 

Configuring from name and from email in WP Mail SMTP plugin

You can also configure the return path to match the from address. This way, bounced emails will be returned to the sender’s email address. If you don’t want your From Email to be the same as the return path, keep the box unchecked.

Now you have to scroll down and choose ‘Other SMTP’ as your mailer. Here, you’ll need the credentials you copied from the Mailtrap account:

  • SMTP Host: live.smtp.mailtrap.io (transactional) or bulk.smtp.mailtrap.io (bulk marketing emails)
  • Encryption: None, SSL, or TLS (we recommend choosing either SSL or TLS for security reasons)
  • SMTP Port: 465 (for SSL) and 587 (for TLS – Recommended)
  • SMTP Authentication: On or off (always toggle On) 
  • SMTP Username: api 
  • SMTP Password: SMTP password you copied from your account (for extra security measures, you can store your password in the wp-config.php file. Refer to these instructions for more info on wp-config.php).

Click ‘Save Settings’ and your mailer will be saved. To make sure everything is set up correctly, navigate to the ‘Email Test’ tab, toggle HTML on or off, enter the desired email address, and press ‘Send Email’. 

Sending a test email with WP Mail SMTP

When the email lands in your inbox, go back to your Email Sending account and press ‘Verify Setup’ in the ‘API and SMTP’ tab. 

Verifying the setup in Mailtrap Email API account

More WordPress SMTP plugins to consider 

WP Mail SMTP isn’t the only plugin that allows you to tweak email server settings for your WordPress website. In fact, there are hundreds of them. How do you choose the right one? Check the following details:

  • Number of active installations; 
  • Compatibility/tests with the latest WordPress version;
  • Frequency of maintenance and updates; 
  • Reviews.

For example, the WP SMTP Config plugin hasn’t been tested for the latest three WordPress updates and hasn’t been updated for 4 years. This means that this plugin is no longer maintained or supported. It’s not the best idea to opt for such an option. 

We’ve picked out three popular plugins that work properly according to users’ reviews and are regularly updated and tested.

Easy WP SMTP

Easy WP SMTP is a simple plugin to configure SMTP for WordPress. It uses the PHPMailer library. Its capabilities include:

  • Integration with Gmail, Yahoo, and Hotmail SMTP, as well as SMTP relay services 
  • Debugging and logging
  • Custom email headers
  • Export and import of SMTP settings with an add-on. 

Tweaking Easy WP SMTP settings is fairly easy as it’s similar to WP Mail SMTP. 

Post SMTP – WordPress SMTP Plugin

Post SMTP is an easy-to-use plugin, and on top of SMTP server setup for all mayor providers, it offers the following capabilities:

  • Email logging 
  • Custom email headers along with Cc and Bcc 
  • OAuth 2.0 authentication for Gmail, Hotmail, and Yahoo
  • Post SMTP mobile app
  • Support for Gmail, Mailgun, Mandrill, Sendgrid, SendPulse, Mailjet, Zoho, Amazon SES, Postmark, and more
  • MainWP/Post Tool Integration
  • Auto resend for failed emails
  • Email failure notifications that can be sent to an admin email or Slack 

Icegram Express 

Icegram Express (formerly called Email Subscribers & Newsletters) isn’t just an SMTP plugin – it’s an email marketing tool. It automates the sending of newsletters and managing subscribers from your WordPress website. The plugin enables you to set your mailer or use other SMTP plugins if they are already configured.

The main capabilities include:

  • HTML editor 
  • Broadcast sending
  • Email scheduling
  • Subscription box
  • Sent emails report
  • Support for localization and internationalization
  • User access control 
Icegram Express configuration

Note: Custom SMTP and other mailers are only available with a paid subscription. 

FluentSMTP

FluentSMTP offers the most advanced SMTP features despite being a free plugin. The plugin boasts email logging as well as some of the smartest features for free. Its wide range of features includes:

  • Support for multiple connections and secondary SMTP
  • Integration with Gmail, Outlook, Amazon SES, Mailgun, SendGrid, Brevo, Sparkpost, Netcore, Postmark & Elastic Email
  • Email logging
  • Weekly email summary notification
  • Real-time email failure notification via Telegram, Discord & Slack

Configuring FluentSMTP also doesn’t take much effort. With its built-in setup wizard, you can fix your WordPress email delivery within 2 minutes!

How to test emails via SMTP with Mailtrap 

Now that your mailer is set up, it’s time to test emails. Not only is this essential for ensuring the SMTP connection operates correctly, but it’s also important to validate HTML/CSS and check the spam score. You can do all of that with Mailtrap Email Testing

Email Testing is an Email Sandbox that allows you to inspect and debug emails in secure dev and QA environments without spamming users. It enables developers to automate test flows with flexible API, check email headers, inspect HTML/CSS, and get detailed spam analysis. 

Email Testing can be integrated with your WordPress website using the PHPMailer library or SMTP credentials. 

Log into your Mailtrap account and navigate to the ‘Email Testing’ tab. Enter ‘Inboxes’, select the appropriate inbox and find the ‘SMTP Settings’ tab. Under ‘Integrations’, choose PHPMailer from the dropdown menu. Copy the generated code with your credentials in it and paste it into your PHPMailer script:

$phpmailer = new PHPMailer();
$phpmailer->isSMTP();
$phpmailer->Host = 'sandbox.smtp.mailtrap.io';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 2525;
$phpmailer->Username = 'hb76m953410544';
$phpmailer->Password = 'j368826db440q3';

If you’re using an SMTP plugin, configure it to use the Email Testing credentials. To view them, press ‘Show Credential’ under ‘SMTP Settings’. Copy those credentials and paste them into your plugin’s settings. 

Both Email Sending and Email Testing are part of the Mailtrap Email Delivery Platform. This means that you can test, send, and control your email infrastructure all in one place. 

Thanks for reading and good luck with your WordPress SMTP setup! 

Article by Diana Lepilkina Content Specialist @Mailtrap

Comments

3 replies

Jared Mitchell

WP 5.5 has upgraded.

The PHPMailer library just got a major update, going from version 5.2.27 to 6.1.6.

This broke the mailtrap plugin due to class reference

public function mailer_setup(PHPMailer $phpmailer)

Needs to be update to

public function mailer_setup(PHPMailerPHPMailerPHPMailer $phpmailer)

While I found this in a plugin it also applies to the above function reference

Naseem

you are a life saver. thank you

Diana Lepilkina

Hello Jared, thanks for reporting this!
We have updated this post accordingly. However, we don’t have a Mailtrap plugin for WordPress — we know there is a couple of plugins on their marketplace but they are not official.

Comments are closed.