WordPress.org

Make WordPress Core

Ticket #40810: 40810.diff

File 40810.diff, 1.5 KB (added by Mte90, 21 months ago)

refreshed and merged

  • src/wp-includes/pluggable.php

    diff --git src/wp-includes/pluggable.php src/wp-includes/pluggable.php
    index e5b3e9f8c1..211e10a190 100644
    if ( ! function_exists( 'wp_mail' ) ) : 
    330330
    331331                if ( ! isset( $from_email ) ) {
    332332                        // Get the site domain and get rid of www.
    333                         $sitename = strtolower( $_SERVER['SERVER_NAME'] );
     333                        // If SERVER_NAME is not available, hostname will be used.
     334                        if ( !empty ( $_SERVER['SERVER_NAME'] ) ) {
     335                                $sitename = strtolower( $_SERVER['SERVER_NAME'] );
     336                        } else {
     337                                $sitename = strtolower( php_uname( 'n' ));
     338                        }
    334339                        if ( substr( $sitename, 0, 4 ) == 'www.' ) {
    335340                                $sitename = substr( $sitename, 4 );
    336341                        }
  • tests/phpunit/tests/mail.php

    diff --git tests/phpunit/tests/mail.php tests/phpunit/tests/mail.php
    index 951615136b..10f6e29045 100644
    class Tests_Mail extends WP_UnitTestCase { 
    359359
    360360                $this->assertEquals( '', $mailer->Sender );
    361361        }
     362 
     363  /**
     364         * Test that the From parameter has been set in phpmailer instance and not kept default.
     365         * Even in the case when SERVER_NAME is not available.
     366         *
     367         * @ticket 40810
     368         */
     369        public function test_wp_mail_from_not_default() {
     370                $_SERVER['SERVER_NAME'] = '';
     371                wp_mail( 'user@example.org', 'Testing the From field', 'The From field should not be default.' );
     372   
     373                $mailer = tests_retrieve_phpmailer_instance();
     374
     375                $this->assertNotEquals( 'root@localhost', $mailer->From );
     376        }
    362377
    363378        /**
    364379         * @ticket 35598