Ticket #40810: 40810 - getmxrr.diff
| File 40810 - getmxrr.diff, 2.1 KB (added by , 7 years ago) |
|---|
-
src/wp-includes/pluggable.php
diff --git src/wp-includes/pluggable.php src/wp-includes/pluggable.php index d46a410638..eea96c152b 100644
if ( ! function_exists( 'wp_mail' ) ) : 329 329 */ 330 330 331 331 if ( ! isset( $from_email ) ) { 332 // Get the site domain and get rid of www. 333 $sitename = strtolower( $_SERVER['SERVER_NAME'] ); 334 if ( substr( $sitename, 0, 4 ) == 'www.' ) { 335 $sitename = substr( $sitename, 4 ); 332 // Loop through list of possible domain names, use the first one found. 333 $urls = array( @$_SERVER['SERVER_NAME'], get_site_url(), get_home_url(), php_uname( 'n' ), 'localhost' ); 334 foreach ( $urls as $u ) { 335 // Remove optional url scheme, port and path information. 336 $u = preg_replace( '#^[^/]*//+([^/:]+).*$#', '\1', strtolower( $u ) ); 337 if ( ! empty( $u ) ) { 338 $sitename = $u; 339 // Found a domain name, now try to find a suitable mail server. This removes prefixes 340 // like `www.`, `staging.` and `dev.`. If no server found, just use the full domain name. 341 while( ! empty($u) && strpos( $u, '.' ) !== false ) { 342 $hosts = array(); 343 if ( getmxrr( $u, $hosts ) ) { 344 $sitename = $u; 345 break; 346 } 347 $u = preg_replace( '/^(.*?)\\./' , '' , $u ); 348 } 349 break; 350 } 336 351 } 337 352 338 353 $from_email = 'wordpress@' . $sitename; -
tests/phpunit/tests/mail.php
diff --git tests/phpunit/tests/mail.php tests/phpunit/tests/mail.php index 951615136b..bf4c6ef0df 100644
class Tests_Mail extends WP_UnitTestCase { 360 360 $this->assertEquals( '', $mailer->Sender ); 361 361 } 362 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 } 377 363 378 /** 364 379 * @ticket 35598 365 380 */