> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sending e-mail in WordPress

> Set up WordPress to send emails via SMTP using a plugin or custom code.

This article describes how to configure WordPress to send e-mail messages using SMTP authentication. You can use a third-party WordPress plugin to do this, or you can write your own code in a custom WordPress plugin.

## Method #1: Using a third-party plugin

There are many WordPress plugins that provide e-mail functionality. One of the most popular and well-known plugins is [WP Mail SMTP](http://wordpress.org/plugins/wp-mail-smtp), which enables you to configure e-mail settings that are compatible with hosting.com servers.

### Installing the WP Mail SMTP plugin

To install the WP Mail SMTP plugin, follow these steps:

1. Log in to your WordPress site as the administrator.

2. In the left-hand pane, click **Plugins**.

3. Click **Add New**.

4. In the **Search Plugins** text box, type `mail smtp`, and then press Enter.

5. Locate **WP Mail SMTP by WPForms**, and then click **Install Now**.

6. After WordPress finishes installing the plugin, click **Activate**.

### Configuring the WP Mail SMTP plugin

To configure the WP Mail SMTP plugin to work with your account, follow these steps:

1. Log in to your WordPress site as the administrator.

2. In the left-hand pane, click **WP Mail SMTP**, and then click **Settings**. The **WP Mail SMTP** general settings page appears.

3. Under **Mail**, in the **From Email** text box, type the e-mail address you want to use as the sender.
   > 🚧 Important
   >
   > This e-mail address must exist on your account.

4. In the **From Name** text box, type the name you want to associate with the e-mail address you specified in step 3.

5. Under **Return Path**, select the **Set the return-path to match the From Email** check box.

6. Under **Mailer**, select **Other SMTP**.

7. Under **Other SMTP**, in the **SMTP Host** text box, type the full server name for your account.
   > 📘 Note
   >
   > For information about how to determine your account's server name, please see [this article](/docs/determining-your-accounts-server-name).

8. Choose *one* of the following configurations:

* If you want to use encryption, in the **SMTP Port** text box type `465`, and then under **Encryption**, select **SSL**.

* If you do not want to use encryption, in the **SMTP Port** text box type `25`, and then under **Encryption**, select **None**.

<Note>
  hosting.com strongly recommends you use encryption whenever possible.
</Note>

9. Under **Authentication**, select **On**.

10. In the **SMTP Username** text box, type the e-mail address you specified in step 3.

11. In the **SMTP Password** text box, type the password for the e-mail account you specified in step 10.

12. Click **Save Settings**.

<Tip>
  You should test the new configuration to make sure that it works. To do this, follow these steps:

  * Click the **Email Test** tab, and then in the **Send To** text box, type a valid external e-mail address where you can receive a test message.

  * Click **Send Email**. You should receive a test message at the e-mail address you specified in the previous step. If you do not receive a message, check the settings you provided in steps 3 to 11, and then try again.
</Tip>

## Method #2: Using the WordPress API

Instead of using a third-party plugin to handle e-mail for your site, you can develop your own custom code and use the [wp\_mail()](https://developer.wordpress.org/reference/functions/wp_mail/) function in the WordPress API.

<Note>
  The following procedure demonstrates how to send e-mail messages using SMTP authentication. The broader topic of how to write a plugin is beyond the scope of this article. For information about how to get started writing a WordPress plugin, please visit [https://developer.wordpress.org/plugins](https://developer.wordpress.org/plugins).
</Note>

To send e-mail messages with SMTP authentication using the WordPress API, follow these steps:

1. In the *wp-config.php* file, copy and paste the following code:

```
define( 'SMTP_HOST', 'server.a2hosting.com' );  // hosting.com server name. For example, "mi3-ss10.a2hosting.com"
define( 'SMTP_AUTH', true );
define( 'SMTP_PORT', '465' );
define( 'SMTP_SECURE', 'ssl' );
define( 'SMTP_USERNAME', 'user@example.com' );  // Username for SMTP authentication
define( 'SMTP_PASSWORD', 'password' );          // Password for SMTP authentication
define( 'SMTP_FROM',     'user@example.com' );  // SMTP From address
define( 'SMTP_FROMNAME', 'Kelly Koe' );         // SMTP From name
```

2. Replace the **SMTP\_HOST**, **SMTP\_USERNAME**, **SMTP\_FROM**, and **SMTP\_FROMNAME** values with the settings for your own site, and then save your changes to the *wp-config.php* file.

3. In your plugin code file, copy and paste the following code:

```javascript theme={null}
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->SMTPSecure = SMTP_SECURE;
    $phpmailer->Username   = SMTP_USERNAME;
    $phpmailer->Password   = SMTP_PASSWORD;
    $phpmailer->From       = SMTP_FROM;
    $phpmailer->FromName   = SMTP_FROMNAME;
}
```

4. To send an e-mail message, call the [wp\_mail()](https://developer.wordpress.org/reference/functions/wp_mail/) function. For example:

```
wp_mail("recipient@example.com", "Subject", "Message");
```

WordPress then sends the message using the SMTP authentication settings you defined above.

## More information

For more information about the WP-Mail-SMTP plugin, please visit [https://wordpress.org/plugins/wp-mail-smtp](https://wordpress.org/plugins/wp-mail-smtp).
