Configure WordPress SMTP Settings to Send Emails [2023] (2024)

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.7.1"

Run the composer install command to install the library. To instruct WordPress to require PHPMailer, you should add the following line of code to your plugin or theme file:

require_once( 'path/to/vendor/autoload.php' );

Remember: you should substitute path/to with the actual path to the vendor directory in your WordPress installation.

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 functionuse PHPMailer\PHPMailer\PHPMailer;use PHPMailer\PHPMailer\SMTP;use PHPMailer\PHPMailer\Exception;//Load Composer's autoloaderrequire '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_SMTP_host'; //Set the SMTP server to send through $mail->SMTPAuth = true; //Enable SMTP authentication $mail->Username = 'your_SMTP_username'; //SMTP username $mail->Password = 'your_SMTP_password'; //SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption $mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` //Recipients $mail->setFrom('from@yourdomain.com', 'Mailer'); $mail->addAddress('john.doe@example.com', 'Recipient'); //Add a recipient $mail->addAddress('kate.doe@example.com'); //Name is optional $mail->addReplyTo('info@example.com', 'Information'); $mail->addCC('oliver.doe@example.com'); $mail->addBCC('jason.doe@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 = 'You’re Awesome'; $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.

Configure WordPress SMTP Settings to Send Emails [2023] (1)

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

Configure WordPress SMTP Settings to Send Emails [2023] (2)

More information on White Glove Setup is available here.

Integration using third-party 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 the account is ready to use, choose the ‘Sending Domains’ category and go to the ‘API and SMTP’ tab. Choose SMTP and save those credentials.

Configure WordPress SMTP Settings to Send Emails [2023] (3)

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.

Configure WordPress SMTP Settings to Send Emails [2023] (4)

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.

Configure WordPress SMTP Settings to Send Emails [2023] (5)

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: send.smtp.mailtrap.io
  • Encryption: None, SSL, or TLS (we recommend choosing either SSL or TLS for security reasons)
  • SMTP Port: 465 (for SSL) and 587 (for TLS)
  • 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).
Configure WordPress SMTP Settings to Send Emails [2023] (6)

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’.

Configure WordPress SMTP Settings to Send Emails [2023] (7)

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

Configure WordPress SMTP Settings to Send Emails [2023] (8)

Try Mailtrap Email Sending Now

Integration using third-party API

Finally, you can integrate a third-party API to use WP Mail SMTP.

The free version allows users to connect mailers such as SendLayer, SMTP.com, SendinBlue, Mailgun, SendGrid, Gmail (both free Gmail SMTP and Google Workspace), Postmark, and SparkPost.

The pro version also includes Amazon SES, Zoho Mail, and Office 365/Microsoft Outlook.

To connect these mailers, first, you need to download the plugin and follow the instructions we listed above. Then, you can connect the mailer from the WP Mail SMTP settings page or launch the setup wizard. Naturally, you should have your mailer’s working account to get started.

You’ll need to provide credentials such as the API Key and the domain name and enter From Name and From Email. With some mailers, you may need to define the region of the API endpoint. Check your mailer’s documentation for more information.

The instructions will be similar for all mailers except for Gmail. If you’re using Gmail or Google Workspace email account, you’ll need to generate the Client ID and app password. For more details, refer to our WordPress Gmail SMTP blog post.

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.

Configure WordPress SMTP Settings to Send Emails [2023] (9)

Post SMTP Mailer/Email Log

Post SMTP Mailer/Email Log utilizes Zend_Mail and in addition to the SMTP server setup provides the following capabilities:

  • Email logging
  • Custom email headers along with Cc and Bcc
  • OAuth 2.0 authentication for Gmail, Hotmail, and Yahoo
  • API support for Gmail, Mailgun, Mandrill, Sendgrid, Sendinblue, Postmark, and SparkPost
  • Email failure notifications that can be sent to an admin email or Slack.
Configure WordPress SMTP Settings to Send Emails [2023] (10)

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
Configure WordPress SMTP Settings to Send Emails [2023] (11)

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

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.

Try Mailtrap Email Testing Today

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.

Configure WordPress SMTP Settings to Send Emails [2023] (12)

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 ‘Sandbox’ tab. Enter ‘My Inbox’ created by default 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 = '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.

Configure WordPress SMTP Settings to Send Emails [2023] (13)

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!

Try Mailtrap Now

Alright, let's dive into the intricacies of setting up SMTP for WordPress. I can assure you that this topic is right up my alley.

Now, the article emphasizes the importance of reliable email-sending functionality for WordPress, especially when dealing with transactional emails. The limitations of the default PHP mail function in WordPress are highlighted, such as the inability to easily create HTML templates, embed images, or add attachments.

To overcome these limitations and enhance email deliverability, the article suggests using the Simple Mail Transfer Protocol (SMTP). SMTP not only requires header authentication but also supports security mechanisms like SSL and TLS. The tutorial provides two main options for setting up SMTP in WordPress: using the PHPMailer library or configuring it with a WordPress plugin.

For the PHPMailer approach, it walks you through the process of installing the composer, creating a composer.json file, requiring the PHPMailer library, and configuring PHPMailer settings to use an SMTP server for sending HTML emails with attachments. The provided script is quite comprehensive and should get your WordPress SMTP up and running smoothly.

On the other hand, if you prefer a plugin-based solution, the article introduces the WP Mail SMTP plugin, particularly highlighting the WPForms' White Glove Setup service available for Elite users. This service involves configuring the plugin settings for you, testing the setup, and ensuring everything is ready for reliable email delivery.

Additionally, the article covers the manual setup of WP Mail SMTP with a third-party SMTP server, such as Mailtrap Email Sending, and integrating it using third-party API options. It explains the steps for setting up these services and provides guidelines on connecting them with your WordPress site.

Towards the end, the article mentions alternative SMTP plugins like Easy WP SMTP, Post SMTP Mailer/Email Log, and Icegram Express. It offers criteria for selecting the right plugin, considering factors such as active installations, compatibility with the latest WordPress version, maintenance frequency, and user reviews.

Lastly, it emphasizes the importance of testing your SMTP setup, suggesting the use of Mailtrap Email Testing for inspecting and debugging emails in a secure environment without affecting actual users. The tutorial guides you through the process of integrating Mailtrap with PHPMailer or SMTP credentials to ensure your email infrastructure is functioning correctly.

There you have it—an overview of the key concepts and steps involved in setting up SMTP for WordPress. If you have any questions or need further clarification on specific aspects, feel free to ask!

Configure WordPress SMTP Settings to Send Emails [2023] (2024)

References

Top Articles
Latest Posts
Article information

Author: Neely Ledner

Last Updated:

Views: 6389

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Neely Ledner

Birthday: 1998-06-09

Address: 443 Barrows Terrace, New Jodyberg, CO 57462-5329

Phone: +2433516856029

Job: Central Legal Facilitator

Hobby: Backpacking, Jogging, Magic, Driving, Macrame, Embroidery, Foraging

Introduction: My name is Neely Ledner, I am a bright, determined, beautiful, adventurous, adventurous, spotless, calm person who loves writing and wants to share my knowledge and understanding with you.