* @copyright 2004 - 2009 Andy Prevost
* @copyright 2010 Marcus Bointon
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
require_once realpath('../PHPMailerAutoload.php');
/**
* PHPMailer - PHP email transport unit test class
* Performs authentication tests
*/
class PHPMailerTest extends PHPUnit_Framework_TestCase
{
/**
* Holds the default phpmailer instance.
* @private
* @var PHPMailer
*/
public $Mail;
/**
* Holds the SMTP mail host.
* @public
* @var string
*/
public $Host = '';
/**
* Holds the change log.
* @private
* @var string[]
*/
public $ChangeLog = array();
/**
* Holds the note log.
* @private
* @var string[]
*/
public $NoteLog = array();
/**
* PIDs of any processes we need to kill
* @var array
* @access private
*/
private $pids = array();
/**
* Default include path
* @var string
*/
const INCLUDE_DIR = '../';
/**
* Run before each test is started.
*/
public function setUp()
{
if (file_exists('testbootstrap.php')) {
include 'testbootstrap.php'; //Overrides go in here
}
$this->Mail = new PHPMailer;
$this->Mail->SMTPDebug = 3; //Full debug output
$this->Mail->Priority = 3;
$this->Mail->Encoding = '8bit';
$this->Mail->CharSet = 'iso-8859-1';
if (array_key_exists('mail_from', $_REQUEST)) {
$this->Mail->From = $_REQUEST['mail_from'];
} else {
$this->Mail->From = 'unit_test@phpmailer.example.com';
}
$this->Mail->FromName = 'Unit Tester';
$this->Mail->Sender = '';
$this->Mail->Subject = 'Unit Test';
$this->Mail->Body = '';
$this->Mail->AltBody = '';
$this->Mail->WordWrap = 0;
if (array_key_exists('mail_host', $_REQUEST)) {
$this->Mail->Host = $_REQUEST['mail_host'];
} else {
$this->Mail->Host = 'mail.example.com';
}
if (array_key_exists('mail_port', $_REQUEST)) {
$this->Mail->Port = $_REQUEST['mail_port'];
} else {
$this->Mail->Port = 25;
}
$this->Mail->Helo = 'localhost.localdomain';
$this->Mail->SMTPAuth = false;
$this->Mail->Username = '';
$this->Mail->Password = '';
$this->Mail->addReplyTo('no_reply@phpmailer.example.com', 'Reply Guy');
$this->Mail->Sender = 'unit_test@phpmailer.example.com';
if (strlen($this->Mail->Host) > 0) {
$this->Mail->Mailer = 'smtp';
} else {
$this->Mail->Mailer = 'mail';
}
if (array_key_exists('mail_to', $_REQUEST)) {
$this->setAddress($_REQUEST['mail_to'], 'Test User', 'to');
}
if (array_key_exists('mail_cc', $_REQUEST) and strlen($_REQUEST['mail_cc']) > 0) {
$this->setAddress($_REQUEST['mail_cc'], 'Carbon User', 'cc');
}
}
/**
* Run after each test is completed.
*/
public function tearDown()
{
// Clean global variables
$this->Mail = null;
$this->ChangeLog = array();
$this->NoteLog = array();
foreach ($this->pids as $pid) {
$p = escapeshellarg($pid);
shell_exec("ps $p && kill -TERM $p");
}
}
/**
* Build the body of the message in the appropriate format.
*
* @private
* @return void
*/
public function buildBody()
{
$this->checkChanges();
// Determine line endings for message
if ($this->Mail->ContentType == 'text/html' || strlen($this->Mail->AltBody) > 0) {
$eol = "
\r\n";
$bullet_start = '
';
$bullet_end = "\r\n";
$list_start = "\r\n";
} else {
$eol = "\r\n";
$bullet_start = ' - ';
$bullet_end = "\r\n";
$list_start = '';
$list_end = '';
}
$ReportBody = '';
$ReportBody .= '---------------------' . $eol;
$ReportBody .= 'Unit Test Information' . $eol;
$ReportBody .= '---------------------' . $eol;
$ReportBody .= 'phpmailer version: ' . $this->Mail->Version . $eol;
$ReportBody .= 'Content Type: ' . $this->Mail->ContentType . $eol;
$ReportBody .= 'CharSet: ' . $this->Mail->CharSet . $eol;
if (strlen($this->Mail->Host) > 0) {
$ReportBody .= 'Host: ' . $this->Mail->Host . $eol;
}
// If attachments then create an attachment list
$attachments = $this->Mail->getAttachments();
if (count($attachments) > 0) {
$ReportBody .= 'Attachments:' . $eol;
$ReportBody .= $list_start;
foreach ($attachments as $attachment) {
$ReportBody .= $bullet_start . 'Name: ' . $attachment[1] . ', ';
$ReportBody .= 'Encoding: ' . $attachment[3] . ', ';
$ReportBody .= 'Type: ' . $attachment[4] . $bullet_end;
}
$ReportBody .= $list_end . $eol;
}
// If there are changes then list them
if (count($this->ChangeLog) > 0) {
$ReportBody .= 'Changes' . $eol;
$ReportBody .= '-------' . $eol;
$ReportBody .= $list_start;
for ($i = 0; $i < count($this->ChangeLog); $i++) {
$ReportBody .= $bullet_start . $this->ChangeLog[$i][0] . ' was changed to [' .
$this->ChangeLog[$i][1] . ']' . $bullet_end;
}
$ReportBody .= $list_end . $eol . $eol;
}
// If there are notes then list them
if (count($this->NoteLog) > 0) {
$ReportBody .= 'Notes' . $eol;
$ReportBody .= '-----' . $eol;
$ReportBody .= $list_start;
for ($i = 0; $i < count($this->NoteLog); $i++) {
$ReportBody .= $bullet_start . $this->NoteLog[$i] . $bullet_end;
}
$ReportBody .= $list_end;
}
// Re-attach the original body
$this->Mail->Body .= $eol . $ReportBody;
}
/**
* Check which default settings have been changed for the report.
* @private
* @return void
*/
public function checkChanges()
{
if ($this->Mail->Priority != 3) {
$this->addChange('Priority', $this->Mail->Priority);
}
if ($this->Mail->Encoding != '8bit') {
$this->addChange('Encoding', $this->Mail->Encoding);
}
if ($this->Mail->CharSet != 'iso-8859-1') {
$this->addChange('CharSet', $this->Mail->CharSet);
}
if ($this->Mail->Sender != '') {
$this->addChange('Sender', $this->Mail->Sender);
}
if ($this->Mail->WordWrap != 0) {
$this->addChange('WordWrap', $this->Mail->WordWrap);
}
if ($this->Mail->Mailer != 'mail') {
$this->addChange('Mailer', $this->Mail->Mailer);
}
if ($this->Mail->Port != 25) {
$this->addChange('Port', $this->Mail->Port);
}
if ($this->Mail->Helo != 'localhost.localdomain') {
$this->addChange('Helo', $this->Mail->Helo);
}
if ($this->Mail->SMTPAuth) {
$this->addChange('SMTPAuth', 'true');
}
}
/**
* Add a changelog entry.
* @access private
* @param string $sName
* @param string $sNewValue
* @return void
*/
public function addChange($sName, $sNewValue)
{
$this->ChangeLog[] = array($sName, $sNewValue);
}
/**
* Adds a simple note to the message.
* @public
* @param string $sValue
* @return void
*/
public function addNote($sValue)
{
$this->NoteLog[] = $sValue;
}
/**
* Adds all of the addresses
* @access public
* @param string $sAddress
* @param string $sName
* @param string $sType
* @return boolean
*/
public function setAddress($sAddress, $sName = '', $sType = 'to')
{
switch ($sType) {
case 'to':
return $this->Mail->addAddress($sAddress, $sName);
case 'cc':
return $this->Mail->addCC($sAddress, $sName);
case 'bcc':
return $this->Mail->addBCC($sAddress, $sName);
}
return false;
}
/**
* Check that we have loaded default test params.
* Pretty much everything will fail due to unset recipient if this is not done.
*/
public function testBootstrap()
{
$this->assertTrue(
file_exists('testbootstrap.php'),
'Test config params missing - copy testbootstrap.php to testbootstrap-dist.php and change as appropriate'
);
}
/**
* Test CRAM-MD5 authentication.
* Needs a connection to a server that supports this auth mechanism, so commented out by default
*/
public function testAuthCRAMMD5()
{
$this->Mail->Host = 'hostname';
$this->Mail->Port = 587;
$this->Mail->SMTPAuth = true;
$this->Mail->SMTPSecure = 'tls';
$this->Mail->AuthType = 'CRAM-MD5';
$this->Mail->Username = 'username';
$this->Mail->Password = 'password';
$this->Mail->Body = 'Test body';
$this->Mail->Subject .= ': Auth CRAM-MD5';
$this->Mail->From = 'from@example.com';
$this->Mail->Sender = 'from@example.com';
$this->Mail->clearAllRecipients();
$this->Mail->addAddress('user@example.com');
//$this->assertTrue($this->mail->send(), $this->mail->ErrorInfo);
}
/**
* Test email address validation.
* Test addresses obtained from http://isemail.info
* Some failing cases commented out that are apparently up for debate!
*/
public function testValidate()
{
$validaddresses = array(
'first@iana.org',
'first.last@iana.org',
'1234567890123456789012345678901234567890123456789012345678901234@iana.org',
'"first\"last"@iana.org',
'"first@last"@iana.org',
'"first\last"@iana.org',
'first.last@[12.34.56.78]',
'first.last@[IPv6:::12.34.56.78]',
'first.last@[IPv6:1111:2222:3333::4444:12.34.56.78]',
'first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.56.78]',
'first.last@[IPv6:::1111:2222:3333:4444:5555:6666]',
'first.last@[IPv6:1111:2222:3333::4444:5555:6666]',
'first.last@[IPv6:1111:2222:3333:4444:5555:6666::]',
'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888]',
'first.last@x23456789012345678901234567890123456789012345678901234567890123.iana.org',
'first.last@3com.com',
'first.last@123.iana.org',
'"first\last"@iana.org',
'first.last@[IPv6:1111:2222:3333::4444:5555:12.34.56.78]',
'first.last@[IPv6:1111:2222:3333::4444:5555:6666:7777]',
'first.last@example.123',
'first.last@com',
'"Abc\@def"@iana.org',
'"Fred\ Bloggs"@iana.org',
'"Joe.\Blow"@iana.org',
'"Abc@def"@iana.org',
'user+mailbox@iana.org',
'customer/department=shipping@iana.org',
'$A12345@iana.org',
'!def!xyz%abc@iana.org',
'_somename@iana.org',
'dclo@us.ibm.com',
'peter.piper@iana.org',
'"Doug \"Ace\" L."@iana.org',
'test@iana.org',
'TEST@iana.org',
'1234567890@iana.org',
'test+test@iana.org',
'test-test@iana.org',
't*est@iana.org',
'+1~1+@iana.org',
'{_test_}@iana.org',
'"[[ test ]]"@iana.org',
'test.test@iana.org',
'"test.test"@iana.org',
'test."test"@iana.org',
'"test@test"@iana.org',
'test@123.123.123.x123',
'test@123.123.123.123',
'test@[123.123.123.123]',
'test@example.iana.org',
'test@example.example.iana.org',
'"test\test"@iana.org',
'test@example',
'"test\blah"@iana.org',
'"test\blah"@iana.org',
'"test\"blah"@iana.org',
'customer/department@iana.org',
'_Yosemite.Sam@iana.org',
'~@iana.org',
'"Austin@Powers"@iana.org',
'Ima.Fool@iana.org',
'"Ima.Fool"@iana.org',
'"Ima Fool"@iana.org',
'"first"."last"@iana.org',
'"first".middle."last"@iana.org',
'"first".last@iana.org',
'first."last"@iana.org',
'"first"."middle"."last"@iana.org',
'"first.middle"."last"@iana.org',
'"first.middle.last"@iana.org',
'"first..last"@iana.org',
'"first\"last"@iana.org',
'first."mid\dle"."last"@iana.org',
'"test blah"@iana.org',
'(foo)cal(bar)@(baz)iamcal.com(quux)',
'cal@iamcal(woo).(yay)com',
'cal(woo(yay)hoopla)@iamcal.com',
'cal(foo\@bar)@iamcal.com',
'cal(foo\)bar)@iamcal.com',
'first().last@iana.org',
'pete(his account)@silly.test(his host)',
'c@(Chris\'s host.)public.example',
'jdoe@machine(comment). example',
'1234 @ local(blah) .machine .example',
'first(abc.def).last@iana.org',
'first(a"bc.def).last@iana.org',
'first.(")middle.last(")@iana.org',
'first(abc\(def)@iana.org',
'first.last@x(1234567890123456789012345678901234567890123456789012345678901234567890).com',
'a(a(b(c)d(e(f))g)h(i)j)@iana.org',
'name.lastname@domain.com',
'a@b',
'a@bar.com',
'aaa@[123.123.123.123]',
'a@bar',
'a-b@bar.com',
'+@b.c',
'+@b.com',
'a@b.co-foo.uk',
'"hello my name is"@stutter.com',
'"Test \"Fail\" Ing"@iana.org',
'valid@about.museum',
'shaitan@my-domain.thisisminekthx',
'foobar@192.168.0.1',
'"Joe\Blow"@iana.org',
'HM2Kinsists@(that comments are allowed)this.is.ok',
'user%uucp!path@berkeley.edu',
'first.last @iana.org',
'cdburgess+!#$%&\'*-/=?+_{}|~test@gmail.com',
'first.last@[IPv6:::a2:a3:a4:b1:b2:b3:b4]',
'first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3::]',
'first.last@[IPv6:::]',
'first.last@[IPv6:::b4]',
'first.last@[IPv6:::b3:b4]',
'first.last@[IPv6:a1::b4]',
'first.last@[IPv6:a1::]',
'first.last@[IPv6:a1:a2::]',
'first.last@[IPv6:0123:4567:89ab:cdef::]',
'first.last@[IPv6:0123:4567:89ab:CDEF::]',
'first.last@[IPv6:::a3:a4:b1:ffff:11.22.33.44]',
'first.last@[IPv6:::a2:a3:a4:b1:ffff:11.22.33.44]',
'first.last@[IPv6:a1:a2:a3:a4::11.22.33.44]',
'first.last@[IPv6:a1:a2:a3:a4:b1::11.22.33.44]',
'first.last@[IPv6:a1::11.22.33.44]',
'first.last@[IPv6:a1:a2::11.22.33.44]',
'first.last@[IPv6:0123:4567:89ab:cdef::11.22.33.44]',
'first.last@[IPv6:0123:4567:89ab:CDEF::11.22.33.44]',
'first.last@[IPv6:a1::b2:11.22.33.44]',
'test@test.com',
'test@xn--example.com',
'test@example.com'
);
$invalidaddresses = array(
'first.last@sub.do,com',
'first\@last@iana.org',
'123456789012345678901234567890123456789012345678901234567890' .
'@12345678901234567890123456789012345678901234 [...]',
'first.last',
'12345678901234567890123456789012345678901234567890123456789012345@iana.org',
'.first.last@iana.org',
'first.last.@iana.org',
'first..last@iana.org',
'"first"last"@iana.org',
'"""@iana.org',
'"\"@iana.org',
//'""@iana.org',
'first\@last@iana.org',
'first.last@',
'x@x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.' .
'x23456789.x23456789.x23456789.x23 [...]',
'first.last@[.12.34.56.78]',
'first.last@[12.34.56.789]',
'first.last@[::12.34.56.78]',
'first.last@[IPv5:::12.34.56.78]',
'first.last@[IPv6:1111:2222:3333:4444:5555:12.34.56.78]',
'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:12.34.56.78]',
'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777]',
'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888:9999]',
'first.last@[IPv6:1111:2222::3333::4444:5555:6666]',
'first.last@[IPv6:1111:2222:333x::4444:5555]',
'first.last@[IPv6:1111:2222:33333::4444:5555]',
'first.last@-xample.com',
'first.last@exampl-.com',
'first.last@x234567890123456789012345678901234567890123456789012345678901234.iana.org',
'abc\@def@iana.org',
'abc\@iana.org',
'Doug\ \"Ace\"\ Lovell@iana.org',
'abc@def@iana.org',
'abc\@def@iana.org',
'abc\@iana.org',
'@iana.org',
'doug@',
'"qu@iana.org',
'ote"@iana.org',
'.dot@iana.org',
'dot.@iana.org',
'two..dot@iana.org',
'"Doug "Ace" L."@iana.org',
'Doug\ \"Ace\"\ L\.@iana.org',
'hello world@iana.org',
//'helloworld@iana .org',
'gatsby@f.sc.ot.t.f.i.tzg.era.l.d.',
'test.iana.org',
'test.@iana.org',
'test..test@iana.org',
'.test@iana.org',
'test@test@iana.org',
'test@@iana.org',
'-- test --@iana.org',
'[test]@iana.org',
'"test"test"@iana.org',
'()[]\;:,><@iana.org',
'test@.',
'test@example.',
'test@.org',
'test@12345678901234567890123456789012345678901234567890123456789012345678901234567890' .
'12345678901234567890 [...]',
'test@[123.123.123.123',
'test@123.123.123.123]',
'NotAnEmail',
'@NotAnEmail',
'"test"blah"@iana.org',
'.wooly@iana.org',
'wo..oly@iana.org',
'pootietang.@iana.org',
'.@iana.org',
'Ima Fool@iana.org',
'phil.h\@\@ck@haacked.com',
'foo@[\1.2.3.4]',
//'first."".last@iana.org',
'first\last@iana.org',
'Abc\@def@iana.org',
'Fred\ Bloggs@iana.org',
'Joe.\Blow@iana.org',
'first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.567.89]',
'{^c\@**Dog^}@cartoon.com',
//'"foo"(yay)@(hoopla)[1.2.3.4]',
'cal(foo(bar)@iamcal.com',
'cal(foo)bar)@iamcal.com',
'cal(foo\)@iamcal.com',
'first(12345678901234567890123456789012345678901234567890)last@(1234567890123456789' .
'01234567890123456789012 [...]',
'first(middle)last@iana.org',
'first(abc("def".ghi).mno)middle(abc("def".ghi).mno).last@(abc("def".ghi).mno)example' .
'(abc("def".ghi).mno). [...]',
'a(a(b(c)d(e(f))g)(h(i)j)@iana.org',
'.@',
'@bar.com',
'@@bar.com',
'aaa.com',
'aaa@.com',
'aaa@.123',
'aaa@[123.123.123.123]a',
'aaa@[123.123.123.333]',
'a@bar.com.',
'a@-b.com',
'a@b-.com',
'-@..com',
'-@a..com',
'invalid@about.museum-',
'test@...........com',
'"Unicode NULL' . chr(0) . '"@char.com',
'Unicode NULL' . chr(0) . '@char.com',
'first.last@[IPv6::]',
'first.last@[IPv6::::]',
'first.last@[IPv6::b4]',
'first.last@[IPv6::::b4]',
'first.last@[IPv6::b3:b4]',
'first.last@[IPv6::::b3:b4]',
'first.last@[IPv6:a1:::b4]',
'first.last@[IPv6:a1:]',
'first.last@[IPv6:a1:::]',
'first.last@[IPv6:a1:a2:]',
'first.last@[IPv6:a1:a2:::]',
'first.last@[IPv6::11.22.33.44]',
'first.last@[IPv6::::11.22.33.44]',
'first.last@[IPv6:a1:11.22.33.44]',
'first.last@[IPv6:a1:::11.22.33.44]',
'first.last@[IPv6:a1:a2:::11.22.33.44]',
'first.last@[IPv6:0123:4567:89ab:cdef::11.22.33.xx]',
'first.last@[IPv6:0123:4567:89ab:CDEFF::11.22.33.44]',
'first.last@[IPv6:a1::a4:b1::b4:11.22.33.44]',
'first.last@[IPv6:a1::11.22.33]',
'first.last@[IPv6:a1::11.22.33.44.55]',
'first.last@[IPv6:a1::b211.22.33.44]',
'first.last@[IPv6:a1::b2::11.22.33.44]',
'first.last@[IPv6:a1::b3:]',
'first.last@[IPv6::a2::b4]',
'first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3:]',
'first.last@[IPv6::a2:a3:a4:b1:b2:b3:b4]',
'first.last@[IPv6:a1:a2:a3:a4::b1:b2:b3:b4]',
//This is a valid RCC5322 address, but we don't want to allow it for obvious reasons!
"(\r\n RCPT TO:user@example.com\r\n DATA \\\nSubject: spam10\\\n\r\n Hello,\r\n".
" this is a spam mail.\\\n.\r\n QUIT\r\n ) a@example.net"
);
// IDNs in Unicode and ASCII forms.
$unicodeaddresses = array(
'first.last@bücher.ch',
'first.last@кто.рф',
'first.last@phplíst.com',
);
$asciiaddresses = array(
'first.last@xn--bcher-kva.ch',
'first.last@xn--j1ail.xn--p1ai',
'first.last@xn--phplst-6va.com',
);
$goodfails = array();
foreach (array_merge($validaddresses, $asciiaddresses) as $address) {
if (!PHPMailer::validateAddress($address)) {
$goodfails[] = $address;
}
}
$badpasses = array();
foreach (array_merge($invalidaddresses, $unicodeaddresses) as $address) {
if (PHPMailer::validateAddress($address)) {
$badpasses[] = $address;
}
}
$err = '';
if (count($goodfails) > 0) {
$err .= "Good addresses that failed validation:\n";
$err .= implode("\n", $goodfails);
}
if (count($badpasses) > 0) {
if (!empty($err)) {
$err .= "\n\n";
}
$err .= "Bad addresses that passed validation:\n";
$err .= implode("\n", $badpasses);
}
$this->assertEmpty($err, $err);
//For coverage
$this->assertTrue(PHPMailer::validateAddress('test@example.com', 'auto'));
$this->assertFalse(PHPMailer::validateAddress('test@example.com.', 'auto'));
$this->assertTrue(PHPMailer::validateAddress('test@example.com', 'pcre'));
$this->assertFalse(PHPMailer::validateAddress('test@example.com.', 'pcre'));
$this->assertTrue(PHPMailer::validateAddress('test@example.com', 'pcre8'));
$this->assertFalse(PHPMailer::validateAddress('test@example.com.', 'pcre8'));
$this->assertTrue(PHPMailer::validateAddress('test@example.com', 'php'));
$this->assertFalse(PHPMailer::validateAddress('test@example.com.', 'php'));
$this->assertTrue(PHPMailer::validateAddress('test@example.com', 'noregex'));
$this->assertFalse(PHPMailer::validateAddress('bad', 'noregex'));
}
/**
* Test injecting a custom validator.
*/
public function testCustomValidator()
{
//Inject a one-off custom validator
$this->assertTrue(
PHPMailer::validateAddress(
'user@example.com',
function ($address) {
return (strpos($address, '@') !== false);
}
),
'Custom validator false negative'
);
$this->assertFalse(
PHPMailer::validateAddress(
'userexample.com',
function ($address) {
return (strpos($address, '@') !== false);
}
),
'Custom validator false positive'
);
//Set the default validator to an injected function
PHPMailer::$validator = function ($address) {
return ('user@example.com' === $address);
};
$this->assertTrue(
$this->Mail->addAddress('user@example.com'),
'Custom default validator false negative'
);
$this->assertFalse(
//Need to pick a failing value which would pass all other validators
//to be sure we're using our custom one
$this->Mail->addAddress('bananas@example.com'),
'Custom default validator false positive'
);
//Set default validator to PHP built-in
PHPMailer::$validator = 'php';
$this->assertFalse(
//This is a valid address that FILTER_VALIDATE_EMAIL thinks is invalid
$this->Mail->addAddress('first.last@example.123'),
'PHP validator not behaving as expected'
);
}
/**
* Word-wrap an ASCII message.
*/
public function testWordWrap()
{
$this->Mail->WordWrap = 40;
$my_body = str_repeat(
'Here is the main body of this message. It should ' .
'be quite a few lines. It should be wrapped at ' .
'40 characters. Make sure that it is. ',
10
);
$nBodyLen = strlen($my_body);
$my_body .= "\n\nThis is the above body length: " . $nBodyLen;
$this->Mail->Body = $my_body;
$this->Mail->Subject .= ': Wordwrap';
$this->buildBody();
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
}
/**
* Word-wrap a multibyte message.
*/
public function testWordWrapMultibyte()
{
$this->Mail->WordWrap = 40;
$my_body = str_repeat(
'飛兒樂 團光茫 飛兒樂 團光茫 飛兒樂 團光茫 飛兒樂 團光茫 ' .
'飛飛兒樂 團光茫兒樂 團光茫飛兒樂 團光飛兒樂 團光茫飛兒樂 團光茫兒樂 團光茫 ' .
'飛兒樂 團光茫飛兒樂 團飛兒樂 團光茫光茫飛兒樂 團光茫. ',
10
);
$nBodyLen = strlen($my_body);
$my_body .= "\n\nThis is the above body length: " . $nBodyLen;
$this->Mail->Body = $my_body;
$this->Mail->Subject .= ': Wordwrap multibyte';
$this->buildBody();
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
}
/**
* Test low priority.
*/
public function testLowPriority()
{
$this->Mail->Priority = 5;
$this->Mail->Body = 'Here is the main body. There should be ' .
'a reply to address in this message.';
$this->Mail->Subject .= ': Low Priority';
$this->Mail->addReplyTo('nobody@nobody.com', 'Nobody (Unit Test)');
$this->buildBody();
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
}
/**
* Simple plain file attachment test.
*/
public function testMultiplePlainFileAttachment()
{
$this->Mail->Body = 'Here is the text body';
$this->Mail->Subject .= ': Plain + Multiple FileAttachments';
if (!$this->Mail->addAttachment(realpath(self::INCLUDE_DIR . 'examples/images/phpmailer.png'))) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
if (!$this->Mail->addAttachment(__FILE__, 'test.txt')) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
$this->buildBody();
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
}
/**
* Simple plain string attachment test.
*/
public function testPlainStringAttachment()
{
$this->Mail->Body = 'Here is the text body';
$this->Mail->Subject .= ': Plain + StringAttachment';
$sAttachment = 'These characters are the content of the ' .
"string attachment.\nThis might be taken from a " .
'database or some other such thing. ';
$this->Mail->addStringAttachment($sAttachment, 'string_attach.txt');
$this->buildBody();
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
}
/**
* Plain quoted-printable message.
*/
public function testQuotedPrintable()
{
$this->Mail->Body = 'Here is the main body';
$this->Mail->Subject .= ': Plain + Quoted-printable';
$this->Mail->Encoding = 'quoted-printable';
$this->buildBody();
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
//Check that a quoted printable encode and decode results in the same as went in
$t = file_get_contents(__FILE__); //Use this file as test content
//Force line breaks to UNIX-style
$t = str_replace(array("\r\n", "\r"), "\n", $t);
$this->assertEquals(
$t,
quoted_printable_decode($this->Mail->encodeQP($t)),
'Quoted-Printable encoding round-trip failed'
);
$this->assertEquals(
$this->Mail->encodeQP($t),
$this->Mail->encodeQPphp($t),
'Quoted-Printable BC wrapper failed'
);
//Force line breaks to Windows-style
$t = str_replace("\n", "\r\n", $t);
$this->assertEquals(
$t,
quoted_printable_decode($this->Mail->encodeQP($t)),
'Quoted-Printable encoding round-trip failed (Windows line breaks)'
);
}
/**
* Send an HTML message.
*/
public function testHtml()
{
$this->Mail->isHTML(true);
$this->Mail->Subject .= ": HTML only";
$this->Mail->Body = <<
HTML email test
PHPMailer does HTML!
This is a test message written in HTML.
Go to https://github.com/PHPMailer/PHPMailer/
for new versions of PHPMailer.
Thank you!