WordPress SMTP Settings
Tags: php, tutorial, wordpress, webdev
Published: 2022-10-10 13:10:23

If you have a website running on WordPress and need to send newsletters or email notifications, then you have to perform additional setup actions. The native WordPress functionality for email sending uses the PHP mail() function, which is not the best option. First, its capabilities are pretty limited so that you can’t easily build HTML templates, embed images, or add attachments. Second, PHP mail() is poor with proper [email headers](https://mailtrap.io/blog/email-headers/). And this is just one of the reasons why such emails frequently land in spam folders. The latter increases the risk of lowering your domain reputation with mass emails. 

Some WordPress hosts, like [One](https://www.one.com/en/), [Warpgate](https://warpgate.host/), or [Tap](https://thisistap.com/), have an SMTP server already pre-configured for each website – but this is more a rare exception than a trend among [hosting provider](https://www.hostinger.co.uk/wordpress-hosting)s. In most cases, additional steps will need to be made to ensure maximum deliverability for your emails.

To improve [email deliverability](https://mailtrap.io/blog/email-deliverability/), it is recommended to **send all WordPress emails via an [SMTP server](https://mailtrap.io/blog/what-is-smtp-server/)**. And here you have two reliable options:

1. Setup SMTP programmatically.
2. Integrate it with the help of a WordPress plugin.
 
In this article, we will inspect both options so you can choose the one suitable for you. 

## How to configure SMTP settings in WordPress programmatically

This is a tech-savvy method. If you are ready to deal with the email development using PHPMailer and don’t want to depend on WordPress plugins, this option is for you. The setup is quite easy. Go to 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->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();
```

That’s it! Save the file: now you can manage your emails with PHPMailer and your SMTP server. 

_Note: WordPress was updated to the 5.5 version on Aug 11, 2020, that affected the PHPMailer library (support updated from 5.2.27 to 6.1.6.). This update might have caused errors with the previous integrations._

## How to send emails via an SMTP server with a WordPress plugin

An even more popular option for integrating your SMTP server with your WordPress site is installing the appropriate plugin. On the “Plugins” page in WordPress, you will find around 400 results for the “SMTP” search query. How do you choose the right one? Check the following details:

- number of active installations 
- compatibility/tests with the latest WordPress version
- reviews

As a result, we have chosen **four plugins** that have high popularity, work properly according to users’ reviews, and are regularly updated and tested. 

### [WP Mail SMTP by WPForms](https://wordpress.org/plugins/wp-mail-smtp/)

WP Mail SMTP is the most used plugin with over one million active installations. Its free version allows you to integrate your preferred SMTP server or choose one of the built-in email sending providers (Sendinblue, Mailgun, SendGrid, and Gmail). The Pro version adds support for Amazon SES, Outlook, and Office 365.  The more advanced plans allow you to set up DNS verifications as well as test and verify [email delivery](https://mailtrap.io/blog/email-deliverability/). 

In general, the plugin setup is super easy and no coding skills are required. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6fsvglfqbznhzlzv3h1.png)
_Source: WP Mail SMTP_

So you just go to the Settings page, choose a built-in mailer or “Other SMTP” if you use another provider. If you are going to send emails with one of the integrated providers, you will need to login to your account and configure the minimum settings. When using an alternative server, you will have to enter:

- your SMTP hostname
- [SMTP port](https://mailtrap.io/blog/smtp-ports-25-465-587-used-for/)
- encryption method 
- username and password to authenticate

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cwghdf7x5frdbo8y1ezk.png)
_Source: WP Mail SMTP_

Note that in this case, your password will be stored in the website database in plain text. This 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' );
```
Once the configuration file is successfully updated, the password field in the setting will be disabled. If you are new to WordPress, you might want to check [their instructions](https://www.wpbeginner.com/beginners-guide/how-to-edit-wp-config-php-file-in-wordpress/) on editing `wp-config.php`.

### [Easy WP SMTP](https://wordpress.org/plugins/easy-wp-smtp/)

Easy WP SMTP is a similar and simple plugin for WordPress SMTP setup. It also uses the PHPMailer library. Its capabilities include:

- integration with Gmail, Yahoo, and Hotmail SMTP
- debugging and logging
- export and import of SMTP settings


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bi5ovqnq0s5znzkrn9v3.png)
_Source: Easy WP SMTP_

Like in a previous example, you will need to specify hostname, port, encryption and authentication details, as well as set up the “From” name and address. The debugging option lets you send a test message to any email address. 

### [Post SMTP Mailer/Email Log](https://wordpress.org/plugins/post-smtp/)

Post SMTP mailer utilizes Zend_Mail and in addition to the SMTP server setup provides the following capabilities:

- logging and resending all emails 
- custom email headers along with Cc and Bcc 
- OAuth 2.0 authentication for Gmail, Hotmail, and Yahoo
- API support for Gmail, Mailgun, Mandrill, and Sendgrid
- email failure notifications for Chrome


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h8r6x3hgi706mp9q5f45.png)
_Source: Post SMTP Mailer_

### [Email Subscribers & Newsletters](https://wordpress.org/plugins/email-subscribers/)

This plugin is not a pure SMTP integration solution. It provides advanced functionality for sending newsletters and managing subscribers from your WordPress site or blog. The main capabilities include:

- HTML editor 
- broadcast sending
- email scheduling
- subscription box
- sent emails report
- support for localization and internationalization
- user access control 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7unhz30t7k2a04nmez15.png)
_Source: Email Subscribers & Newsletters_

Custom SMTP integration is available in paid subscription plans, which start at $6.50 monthly. 

### [CBX Email SMTP & Logger for WordPress](https://codeboxr.com/product/cbx-email-logger-for-wordpress/)

CBX Email SMTP & Logger for WordPress plugin helps to send emails using SMTP and logs them to keep the record. You can use multiple SMTP services to test email sending, you can also utilize features such as resenting, auto-deleting emails, and previews.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zetdw0dymc1l38g5zz0y.png)
_Source: CBX Email SMTP & Logger for WordPress_

The core plugin is free with all the major features.

## How to integrate WordPress with your email sending provider?

As we have demonstrated above, you can set up an SMTP server manually or with one of the SMTP plugins that are compatible with Namecheap, Hosting Forest, Kinsta, and many other popular [WordPress hosts](https://superbthemes.com/best-wordpress-hosting/).

In addition, the most popular email sending providers have their own official plugins:

- [Elastic Email](https://wordpress.org/plugins/elastic-email-sender/)
- [Mailgun](https://wordpress.org/plugins/mailgun/)
- [Mailjet](https://wordpress.org/plugins/mailjet-for-wordpress/)
- [Pepipost](https://wordpress.org/plugins/pepipost/)
- P[ostmark](https://wordpress.org/plugins/postmark-approved-wordpress-plugin/)
- [SendPulse](https://wordpress.org/plugins/sendpulse-email-marketing-newsletter/)
- [SocketLabs](https://wordpress.org/plugins/socketlabs/)

_Note: We listed only those plugins, which have been updated in the last year_

## How to Test Emails via SMTP with Mailtrap

Any method you choose to set up sending your emails from WordPress via SMTP, you should properly test them before reaching the inboxes of real users. If you use a plugin, you can use its functionality to send test emails to your own inbox. But if you integrate SMTP manually, it is essential to test if email sending actually works. Set [Mailtrap](https://mailtrap.io/) as your SMTP server first: it is a fast and easy way to verify email sending functionality, check email headers, and view your messages rendered by a webmail client.

If you have never used Mailtrap before, you can [create a free account](https://mailtrap.io/register/signup) in just three clicks. Then go to your Mailtrap inbox, copy the necessary settings like hostname, port, your username, and password, and paste them to the WordPress settings file or appropriate plugin tab. Then compose an email and send it. It will be delivered to your Mailtrap inbox right away: 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q1yw731dc93ikybombjf.png)

This way, you can safely test numerous email notifications and different types of messages without flooding your inbox or affecting your domain reputation. 

Once you have verified that your emails look perfect, set your real SMTP server’s credentials and enjoy email sending from your WordPress website.

---

I hope you enjoyed reading our guide on setting SMTP to send emails with a WP plugin that was originally published on Mailtrap Blog: [https://mailtrap.io/blog/wordpress-smtp-settings/](https://mailtrap.io/blog/wordpress-smtp-settings/)