# SMTP with cloudways

**URL:** https://discourse.roots.io/t/smtp-with-cloudways/26472
**Category:** radicle
**Created:** 2023-12-28T22:01:06Z
**Posts:** 11

## Post 1 by @wispyco — 2023-12-28T22:01:06Z

I have radicle running on cloudways, it seems to be running quite well. However cloudways has a SMTP server selection in the server section dashboard. I setup Send Grid and it sends email from the test dashboard on the server in cloudways, but when I try to send email from wordpress which is running on that server it doesn’t work I can’t send user invites.

I can add whatever relevant information or code you need, but I don’t know what to add.

Thanks ahead of time.

---

## Post 2 by @ben — 2023-12-28T22:09:02Z

You need to configure WordPress’s SMTP settings to match your provider

Radicle doesn’t have support for this out of the box right now, but I’ll likely add this as a mu-plugin in the next version since you’ve brought it up :smiley:

```
/**
 * Configure SMTP from environment variables
 */
add_filter('phpmailer_init', function ($mail) {
    $mail->isSMTP();

    $mail->SMTPAuth = true;
    $mail->Host = env('WP_ENV') === 'development' ? 'localhost' : env('WP_SMTP_HOST');
    $mail->Port = env('WP_ENV') === 'development' ? 1025 : 587;
    $mail->Username = env('WP_SMTP_USERNAME');
    $mail->Password = env('WP_SMTP_PASSWORD');
    $mail->Timeout = 10;

    $mail->setFrom(
        env('WP_SMTP_FORCEFROM'),
        env('WP_SMTP_FORCEFROMNAME')
    );
});
```

Props to @Log1x for the code above, which I use on a couple of my sites

---

## Post 3 by @wispyco — 2023-12-28T22:12:18Z

thank you ben where does this add\_filter go in the radicle stack? wp-config?

---

## Post 4 by @ben — 2023-12-28T22:16:05Z

No, that would go into a mu-plugin, like `public/content/mu-plugins/smtp.php`, and it requires you to configure the environment values from the `.env` file.

You could also use one of the many available SMTP WordPress plugins that handle this with a GUI.

---

## Post 5 by @wispyco — 2023-12-28T22:17:40Z

Oh I see I will attempt this as a Must Use plugin first and if i can’t get it to work I will try a GUI, thank you.

---

## Post 6 by @wispyco — 2023-12-28T22:34:36Z

Do I have to clear cache, or restart server after setting up the MU plugin and where can I check for logs, or turn logs on?

---

## Post 7 by @wispyco — 2023-12-28T22:47:53Z

I would like to get the MU plugin working, if not just for better understanding. I can see it in wordpress the environment variables are there I am tailing the `appplication.log` file but I don’t see any logs when i try and send a email is there something I can turn on to get visibility @ben

---

## Post 8 by @ben — 2023-12-28T23:05:45Z

You could do try something like:

```
use Illuminate\Support\Facades\Log;

add_action('wp_mail_failed', function ($wp_error) {
    $error_data = print_r($wp_error->get_error_data(), true);
    $error_message = $wp_error->get_error_message();
    Log::debug("Mail failed to send. Error: $error_message, Data: $error_data");
});
```

I haven’t tested this — GPT-assisted code :sweat_smile:

---

## Post 9 by @csorrentino — 2023-12-29T00:32:29Z

it seems like you’re close to getting that working but, if you can’t, you might try the package @Log1x made before moving on to GUI plugins: [GitHub - Log1x/wp-smtp: Simple package for handling WordPress SMTP with .env when using the Roots stack.](https://github.com/Log1x/wp-smtp)

---

## Post 10 by @wispyco — 2024-01-01T14:02:32Z

Thank you Ben got it working this morning, was pretty tired when I was working on it Thursday and I hadn’t set the wp\_env variable to production on the server.

---

## Post 11 by @wispyco — 2024-01-01T14:05:59Z

I did try this it didn’t seem to work for me, but I got Ben’s solution working.
