Getting empty string from "$_SERVER['SERVER_NAME']"

So I was having an issue with the email sending functionality which I narrowed down to “$sitename” (from pluggabble.php) evaluating to an empty string:

php_1    | NOTICE: PHP message:
php_1    | NOTICE: PHP message: WP_Error Object
php_1    | (
php_1    |     [errors] => Array
php_1    |         (
php_1    |             [wp_mail_failed] => Array
php_1    |                 (
php_1    |                     [0] => Invalid address:  (setFrom) wordpress@
php_1    |                 )
php_1    |         )

I plan on open sourcing my setup pretty soon and provide reproduction steps for this issue, just posting here so I won’t forget about it. Meanwhile I’ve made a little mu-plugin as a workaround, if anyone is interested:

<?php
/**
 * Plugin Name:  Override Email From
 * Plugin URI:   https://yetanothernerd.xyz/
 * Description:  Workaround for the "Invalid address:  (setFrom) wordpress@" issue
 * Version:      1.0.0
 * Author:       Yan Minari
 * Author URI:   https://yetanothernerd.xyz/
 * License:      UNLICENSED
 */

add_filter('wp_mail_from', 'new_mail_from');

function new_mail_from($old) {
    return 'no-reply@domain.com';
}

This topic was automatically closed after 42 days. New replies are no longer allowed.