# WordPress and WooCommerce

> Step by step for WordPress (and WooCommerce) to send email through Couryo's SMTP with any SMTP plugin, or without a plugin, with a code snippet.

Source: https://couryo.com/en/docs/wordpress

By default, WordPress sends through the hosting server's `mail()` function. Without authentication for your domain, those emails (password resets, WooCommerce orders, contact forms) land in spam or never arrive. Switching to authenticated SMTP sends them signed with your domain.

## Before you start

1. In Couryo, [verify the site's domain](https://couryo.com/en/docs/domains.md) (for example, `example.com`).
2. Create an API key with the `send` scope. It is the SMTP password.

## With an SMTP plugin

Any generic SMTP plugin works (FluentSMTP, WP Mail SMTP, Post SMTP and others). Field names vary a little between them; the values are these:

1. In **Plugins > Add New**, install and activate the SMTP plugin you prefer.
2. In the plugin settings, choose **Other SMTP** (or "generic SMTP").
3. Fill in:

| Field | Value |
|---|---|
| From Email | an address on the verified domain, such as `no-reply@example.com` |
| From Name | your store or site name |
| Force From Email | on, so other plugins cannot change the address |
| SMTP Host | `smtp.couryo.com` |
| Encryption | `TLS` (STARTTLS) |
| Port | `587` (with `SSL`, use `465`) |
| Authentication | on |
| Username | `couryo` |
| Password | your API key (`ck_live_...`) |

4. Save and use the plugin's **test email** to send yourself a message.
5. In the Couryo dashboard, under **Emails**, the message shows up with its timeline and the destination server's answer.

> If the plugin accepts the password as a constant in `wp-config.php`, prefer it: the key stays out of the database.

## Without a plugin

Create the file below (a "must-use plugin", always loaded) and put the key in `wp-config.php`:

```php title="wp-config.php"
define('COURYO_API_KEY', 'ck_live_...');
```

```php title="wp-content/mu-plugins/couryo-smtp.php"
<?php
/**
 * Plugin Name: Couryo SMTP
 * Description: Sends WordPress email through Couryo's SMTP.
 */
add_action('phpmailer_init', function ($phpmailer) {
    $phpmailer->isSMTP();
    $phpmailer->Host = 'smtp.couryo.com';
    $phpmailer->Port = 587;
    $phpmailer->SMTPSecure = 'tls'; // STARTTLS; for 465 use 'ssl'
    $phpmailer->SMTPAuth = true;
    $phpmailer->Username = 'couryo';
    $phpmailer->Password = COURYO_API_KEY;
});

add_filter('wp_mail_from', fn () => 'no-reply@example.com');
add_filter('wp_mail_from_name', fn () => 'Example');
```

Test it from the login screen with **Lost your password?**: the reset email should show up in the Couryo dashboard within seconds.

## WooCommerce

WooCommerce emails use the same `wp_mail`, so they already go through Couryo. In **WooCommerce > Settings > Emails**, check:

- the **sender name and address** on the verified domain (the same as the plugin);
- which order emails are on, so you do not send notices nobody reads.

Send invoices and payment slips **as links, not attachments**: attachments like these are common in scams and filters distrust them.

## Common problems

| Symptom | What to do |
|---|---|
| Plugin test fails with `535` | username other than `couryo`, or a key that is invalid, revoked or without the `send` scope |
| `550 5.7.1` | the From is not on a verified domain, or the account is still on level 0 |
| Connection error or timeout | the host may block port 587; try `465` with SSL or `2525` with TLS |
| Some emails still use another sender | turn on **Force From Email** in the plugin |
| Arrives, but in spam | see [Why emails go to spam](https://couryo.com/en/guides/emails-going-to-spam.md) |
