mock_sent);
$_SERVER['SERVER_NAME'] = 'example.com';
wp_mail($to, $subject, $body, $headers);
// We need some better assertions here but these catch the failure for now.
$this->assertEquals($body, $GLOBALS['phpmailer']->mock_sent[0]['body']);
$this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'boundary="----=_Part_4892_25692638.1192452070893"') > 0);
$this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'charset=') > 0);
unset( $_SERVER['SERVER_NAME'] );
}
/**
* @ticket 15448
*/
function test_wp_mail_plain_and_html() {
$to = 'user@example.com';
$subject = 'Test email with plain text and html versions';
$messages = array( 'text/plain' => 'Here is some plain text.',
'text/html' =>'
Here is the HTML ;-)' );
unset($GLOBALS['phpmailer']->mock_sent);
$_SERVER['SERVER_NAME'] = 'example.com';
wp_mail( $to, $subject, $messages );
preg_match( '/boundary="(.*)"/', $GLOBALS['phpmailer']->mock_sent[0]['header'], $matches);
$boundry = $matches[1];
$body = '--' . $boundry . '
Content-Type: text/plain; charset = "UTF-8"
Content-Transfer-Encoding: 8bit
Here is some plain text.
--' . $boundry . '
Content-Type: text/html; charset = "UTF-8"
Content-Transfer-Encoding: 8bit
Here is the HTML ;-)
--' . $boundry . '--
';
// We need some better assertions here but these test the behaviour for now.
$this->assertEquals($body, $GLOBALS['phpmailer']->mock_sent[0]['body']);
unset( $_SERVER['SERVER_NAME'] );
}
/**
* @ticket 17305
*/
function test_wp_mail_rfc2822_addresses() {
$to = "Name ";
$from = "Another Name ";
$cc = "The Carbon Guy ";
$bcc = "The Blind Carbon Guy ";
$subject = "RFC2822 Testing";
$message = "My RFC822 Test Message";
$headers[] = "From: {$from}";
$headers[] = "CC: {$cc}";
$headers[] = "BCC: {$bcc}";
unset($GLOBALS['phpmailer']->mock_sent);
$_SERVER['SERVER_NAME'] = 'example.com';
wp_mail( $to, $subject, $message, $headers );
// WordPress 3.2 and later correctly split the address into the two parts and send them seperately to PHPMailer
// Earlier versions of PHPMailer were not touchy about the formatting of these arguments.
if ( version_compare( $GLOBALS['wp_version'], '3.1.9', '>' ) ) {
$this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);
$this->assertEquals('Name', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][1]);
$this->assertEquals('cc@cc.com', $GLOBALS['phpmailer']->mock_sent[0]['cc'][0][0]);
$this->assertEquals('The Carbon Guy', $GLOBALS['phpmailer']->mock_sent[0]['cc'][0][1]);
$this->assertEquals('bcc@bcc.com', $GLOBALS['phpmailer']->mock_sent[0]['bcc'][0][0]);
$this->assertEquals('The Blind Carbon Guy', $GLOBALS['phpmailer']->mock_sent[0]['bcc'][0][1]);
} else {
$this->assertEquals($to, $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);
$this->assertEquals($cc, $GLOBALS['phpmailer']->mock_sent[0]['cc'][0][0]);
$this->assertEquals($bcc, $GLOBALS['phpmailer']->mock_sent[0]['bcc'][0][0]);
}
$this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);
unset( $_SERVER['SERVER_NAME'] );
}
/**
* @ticket 17305
*/
function test_wp_mail_multiple_rfc2822_to_addresses() {
$to = "Name , Another Name ";
$subject = "RFC2822 Testing";
$message = "My RFC822 Test Message";
unset($GLOBALS['phpmailer']->mock_sent);
$_SERVER['SERVER_NAME'] = 'example.com';
wp_mail( $to, $subject, $message );
// WordPress 3.2 and later correctly split the address into the two parts and send them seperately to PHPMailer
// Earlier versions of PHPMailer were not touchy about the formatting of these arguments.
if ( version_compare( $GLOBALS['wp_version'], '3.1.9', '>' ) ) {
$this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);
$this->assertEquals('Name', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][1]);
$this->assertEquals('another_address@different-tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][0]);
$this->assertEquals('Another Name', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][1]);
} else {
$this->assertEquals('Name ', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);
$this->assertEquals('Another Name ', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][0]);
}
$this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);
unset( $_SERVER['SERVER_NAME'] );
}
function test_wp_mail_multiple_to_addresses() {
$to = "address@tld.com, another_address@different-tld.com";
$subject = "RFC2822 Testing";
$message = "My RFC822 Test Message";
unset($GLOBALS['phpmailer']->mock_sent);
$_SERVER['SERVER_NAME'] = 'example.com';
wp_mail( $to, $subject, $message );
$this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);
$this->assertEquals('another_address@different-tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][0]);
$this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);
unset( $_SERVER['SERVER_NAME'] );
}
/**
* @ticket 18463
*/
function test_wp_mail_to_address_no_name() {
$to = "";
$subject = "RFC2822 Testing";
$message = "My RFC822 Test Message";
unset($GLOBALS['phpmailer']->mock_sent);
$_SERVER['SERVER_NAME'] = 'example.com';
wp_mail( $to, $subject, $message );
// Old PHPMailer blindly accepts the address, the new one santizes it
if ( version_compare( $GLOBALS['wp_version'], '3.1.9', '>' ) )
$this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);
else
$this->assertEquals('', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);
$this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);
unset( $_SERVER['SERVER_NAME'] );
}
/**
* @ticket 23642
*/
function test_wp_mail_return_value() {
// No errors
$this->assertTrue( wp_mail( 'valid@address.com', 'subject', 'body' ) );
// Non-fatal errors
$this->assertTrue( wp_mail( 'valid@address.com', 'subject', 'body', "Cc: invalid-address\nBcc: @invalid.address", ABSPATH . '/non-existant-file.html' ) );
// Fatal errors
$this->assertFalse( wp_mail( 'invalid.address', 'subject', 'body', '', array() ) );
}
}