SMTP with cloudways

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.

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->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;


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


thank you ben where does this add_filter go in the radicle stack? wp-config?

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.

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.

1 Like

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?

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

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:

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.

1 Like

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.

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

1 Like