# Sending from WordPress over SMTP

> Make a WordPress site hosted anywhere send its email through Reggio Digital over SMTP, with a small must-use plugin or an SMTP plugin you already run.

Source: https://reggiodigital.com/developers/guides/wordpress

WordPress sends its email, from password resets to shop orders and contact forms, through one function, and out of the box that function hands mail to whatever the web server has. On most hosts that mail arrives late, lands in spam, or never arrives. Pointing WordPress at us over SMTP sends it from the business's own verified domain instead.

**If we host the site, stop here.** We connect sites on our hosting for you, with nothing to install. [Open a ticket](https://reggiodigital.com/tickets/create) and say which site.

## Before you start

- The from address has to be on a sending domain the account has verified. If the business has not added one yet, they do it under [Sending domains](https://reggiodigital.com/domains/sending). See [the DNS a sending domain needs](https://reggiodigital.com/developers/smtp#the-dns-a-sending-domain-needs).
- Open that domain and choose to connect an app. The page shows the host, username and password you need below.

## With a small must-use plugin

This is the version with nothing to update and no settings screen for someone to change by accident. Put the credentials in `wp-config.php`, above the line that says to stop editing:

wp-config.php:

```php
define('REGGIO_SMTP_HOST', 'YOUR_SMTP_HOST');
define('REGGIO_SMTP_USERNAME', 'YOUR_SMTP_USERNAME');
define('REGGIO_SMTP_PASSWORD', 'YOUR_SMTP_PASSWORD');
define('REGGIO_SMTP_FROM', 'hello@yourdomain.com');
```

wp-content/mu-plugins/reggio-smtp.php:

```php
<?php

/**
 * Plugin Name: Send through Reggio Digital
 */
add_action('phpmailer_init', function ($phpmailer) {
    $phpmailer->isSMTP();
    $phpmailer->Host = REGGIO_SMTP_HOST;
    $phpmailer->Port = 587;
    $phpmailer->SMTPSecure = 'tls';
    $phpmailer->SMTPAutoTLS = true;
    $phpmailer->SMTPAuth = true;
    $phpmailer->Username = REGGIO_SMTP_USERNAME;
    $phpmailer->Password = REGGIO_SMTP_PASSWORD;
});

add_filter('wp_mail_from', fn () => REGGIO_SMTP_FROM);
```

Save the second block as its own file in `wp-content/mu-plugins/`, creating the folder if it is not there. WordPress loads everything in that folder on every request and it cannot be switched off from the admin screens.

Port `587` with `SMTPSecure` set to `tls` connects in plain text and upgrades to an encrypted connection before anything is sent, which is what our service expects. `ssl` expects encryption from the first byte and will time out on this port.

The `wp_mail_from` line matters. WordPress sends as `wordpress@` the site's own hostname unless told otherwise, and if the site's address is not on the verified domain every message is refused.

## With an SMTP plugin you already run

If the site already has an SMTP plugin, such as WP Mail SMTP, FluentSMTP or Post SMTP, use it instead of the code above. Do not run both. In its settings choose the generic or "other SMTP" option, not a named provider, and enter:

| Setting | What to enter |
| --- | --- |
| SMTP host | Copy it from the domain's page. |
| Port | `587` |
| Encryption | `TLS` (sometimes shown as STARTTLS) |
| Authentication | On |
| Username and password | Copy them from the domain's page. |
| From email | An address on the verified domain, such as `hello@yourdomain.com`. Tick "force from email" if the plugin offers it, so other plugins cannot send as a different address. |

Most of these plugins can keep the password in `wp-config.php` rather than in the database. Use that where it is offered.

## Checking it works

Send the plugin's test email, or reset a password, to one of the [test addresses](https://reggiodigital.com/developers/email#testing-without-emailing-anyone). The message appears on the account's [Sent page](https://reggiodigital.com/email/sent) within a minute. If nothing shows up there, WordPress never reached us: check the host and port, and look in the site's error log for the SMTP error.

Some contact form and shop plugins set their own from address per form or per email. Check each one is on the verified domain, or those messages alone will be refused.
