diff --git a/ChangeLog.txt b/ChangeLog.txt index 18bfba7f..eca7690d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,11 +1,52 @@ ChangeLog -NOTE: THIS VERSION OF PHPMAILER IS DESIGNED FOR PHP5/PHP6. IT WILL NOT WORK WITH PHP4. +NOTE: THIS VERSION OF PHPMAILER IS DESIGNED FOR PHP5/PHP6. + IT WILL NOT WORK WITH PHP4. -Version ?? -* replaced deprecated split() -* fixed image file extension checking to retrieve last part of explode() file name -* added code to check for duplicate image filename to eliminate multiple same-name images +Version 5.0.1 (April 08, 2009) +* fixed duplicate attachments issue (inline graphic vs attachment) + +Version 5.0.0 (April 02, 2009) + +* With the release of this version, we are initiating a new version numbering + system to differentiate from the PHP4 version of PHPMailer. +* Most notable in this release is fully object oriented code. +class.smtp.php: +* Refactored class.smtp.php to support new exception handling + code size reduced from 29.2 Kb to 25.6 Kb +* Removed unnecessary functions from class.smtp.php: + public function Expand($name) { + public function Help($keyword="") { + public function Noop() { + public function Send($from) { + public function SendOrMail($from) { + public function Verify($name) { +class.phpmailer.php: +* Refactored class.phpmailer.php with new exception handling +* Changed processing functionality of Sendmail and Qmail so they cannot be + inadvertently used +* removed getFile() function, just became a simple wrapper for + file_get_contents() +* added check for PHP version (will gracefully exit if not at least PHP 5.0) +class.phpmailer.php enhancements +* enhanced code to check if an attachment source is the same as an embedded or + inline graphic source to eliminate duplicate attachments +New /test_script +* We have written a test script you can use to test the script as part of your + installation. Once you press submit, the test script will send a multi-mime + email with either the message you type in or an HTML email with an inline + graphic. Two attachments are included in the email (one of the attachments + is also the inline graphic so you can see that only one copy of the graphic + is sent in the email). The test script will also display the functional + script that you can copy/paste to your editor to duplicate the functionality. +New examples +* All new examples in both basic and advanced modes. Advanced examples show + Exception handling. +PHPDocumentator (phpdocs) documentation for PHPMailer version 5.0.0 +* all new documentation + +Please note: the website has been updated to reflect the changes in PHPMailer +version 5.0.0. http://phpmailer.codeworxtech.com/ Version 2.3 (November 06, 2008) diff --git a/README b/README index 3f0ee3fa..8d48dc05 100644 --- a/README +++ b/README @@ -9,6 +9,31 @@ PHPMailer Full Featured Email Transfer Class for PHP ========================================== +Version 5.0.0 (April 02, 2009) + +With the release of this version, we are initiating a new version numbering +system to differentiate from the PHP4 version of PHPMailer. + +Most notable in this release is fully object oriented code. + +We now have available the PHPDocumentor (phpdocs) documentation. This is +separate from the regular download to keep file sizes down. Please see the +download area of http://phpmailer.codeworxtech.com. + +We also have created a new test script (see /test_script) that you can use +right out of the box. Copy the /test_script folder directly to your server (in +the same structure ... with class.phpmailer.php and class.smtp.php in the +folder above it. Then launch the test script with: +http://www.yourdomain.com/phpmailer/test_script/index.php +from this one script, you can test your server settings for mail(), sendmail (or +qmail), and SMTP. This will email you a sample email (using contents.html for +the email body) and two attachments. One of the attachments is used as an inline +image to demonstrate how PHPMailer will automatically detect if attachments are +the same source as inline graphics and only include one version. Once you click +the Submit button, the results will be displayed including any SMTP debug +information and send status. We will also display a version of the script that +you can cut and paste to include in your projects. Enjoy! + Version 2.3 (November 08, 2008) We have removed the /phpdoc from the downloads. All documentation is now on @@ -119,7 +144,7 @@ easy to use classes: AspEmail(tm) and AspMail. Both of these programs are COM components only available on Windows. They are also a little pricey for smaller projects. -Since I do Linux development I’ve missed these tools for my PHP coding. +Since I do Linux development I�ve missed these tools for my PHP coding. So I built a version myself that implements the same methods (object calls) that the Windows-based components do. It is open source and the LGPL license allows you to place the class in your proprietary PHP diff --git a/aboutus.html b/aboutus.html new file mode 100644 index 00000000..b59308cb --- /dev/null +++ b/aboutus.html @@ -0,0 +1,169 @@ + +
+ + + + +PHPMailer is the world's leading email transport class and downloaded an +average of more than 26,000 each month. In March 2009, PHPMailer was downloaded +more than 31,000 times -- that's an average of 1,000 downloads daily. Our thanks +to our new users and loyal users. We understand you have many choices available +to select from and we thank you for select our fast and stable tool for your +website and projects.
+Credits:
+PHPMailer's original founder is Brent Matzelle. The current team is:
+Project Administrator: Andy Prevost (codeworxtech),
+
+codeworxtech@users.sourceforge.net
+Author: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net
+Author: Marcus Bointon (coolbru)
+coolbru@users.sourceforge.net
PHPMailer is used in many projects ranging from Open Source to commercial +packages. Our LGPL licensing terms are very flexible and allow for including +PHPMailer to enhance projects of all types. If you discover PHPMailer being used +in a project, please let us know about it.
+WHY USE OUR TOOLS & WHAT'S IN IT FOR YOU?
+A valid question. We're developers too. We've been writing software, primarily for the internet, for more than 15 years. Along the way, there are two major things that had tremendous impact of our company: PHP and Open Source. PHP is without doubt the most popular platform for the internet. There has been more progress in this area of technology because of Open Source software than in any other IT segment. We have used many open source tools, some as learning tools, some as components in projects we were working on. To us, it's not about popularity ... we're committed to robust, stable, and efficient tools you can use to get your projects in your user's hands quickly. So the shorter answer: what's in it for you? rapid development and rapid deployment without fuss and with straight forward open source licensing.
+Now, here's our team:
+| About Andy Prevost, AKA "codeworxtech". | +About Marcus Bointon, AKA "coolbru". | +
|---|---|
|
+ www.codeworxtech.com for more information. Our company, Worx International Inc., is the publisher of several Open Source applications and developer tools as well as several commercial PHP applications. The Open Source applications are ttCMS and DCP Portal. The Open Source developer tools include QuickComponents (QuickSkin and QuickCache) and now PHPMailer. + We have staff and offices in the United States, Caribbean, the Middle + East, and our primary development center in Canada. Our company is represented by + agents and resellers globally. +Worx International Inc. is at the forefront of developing PHP applications. Our staff are all Zend Certified university educated and experts at object oriented programming. While Worx International Inc. can handle any project from trouble shooting programs written by others all the way to finished mission-critical applications, we specialize in taking projects from inception all the way through to implementation - on budget, and on time. If you need help with your projects, we're the team to get it done right at a reasonable price. +Over the years, there have been a number of tools that have been constant favorites in all of our projects. We have become the project administrators for most of these tools. +Our developer tools are all Open Source. Here's a brief description: +
We're committed to PHP and to the Open Source community. +Opportunities with Worx International Inc.: +
+ Andy Prevost (aka, codeworxtech) + codeworxtech@users.sourceforge.net + + We now also offer website design. hosting, and remote forms processing. Visit WorxStudio.com for more information. + |
+
+ Marcus is the technical director of Synchromedia Limited, a UK-based company providing online business services. Synchromedia's main services are: +Smartmessages.net+
info@hand+
How can we help you?+In addition to our headline services, we also provide consulting, development, hosting and sysadmin services, so if you just need a simple web hosting package, we can do that too. Not surprisingly, we know rather a lot about email, so you can talk to us about that too. +Please contact us if you'd like to know more. +Marcus is a regular attendee at PHP London, and occasionally speaks on email at technical conferences. + |
+
My name is Andy Prevost, AKA "codeworxtech".
-www.codeworxtech.com for more information.
-
WHY USE OUR TOOLS & WHAT'S IN IT FOR YOU?
-A valid question. We're developers too. We've been writing software, primarily for the internet, for more than 15 years. Along the way, there are two major things that had tremendous impact of our company: PHP and Open Source. PHP is without doubt the most popular platform for the internet. There has been more progress in this area of technology because of Open Source software than in any other IT segment. We have used many open source tools, some as learning tools, some as components in projects we were working on. To us, it's not about popularity ... we're committed to robust, stable, and efficient tools you can use to get your projects in your user's hands quickly. So the shorter answer: what's in it for you? rapid development and rapid deployment without fuss and with straight forward open source licensing.
-Now, the introductions:
-Our company, Worx International Inc., is the publisher of several Open Source applications and developer tools as well as several commercial PHP applications. The Open Source applications are ttCMS and DCP Portal. The Open Source developer tools include QuickComponents (QuickSkin and QuickCache) and now PHPMailer. -We have staff and offices in the United States, Caribbean, the Middle -East, and our primary development center in Canada. Our company is represented by -agents and resellers globally.
-Worx International Inc. is at the forefront of developing PHP applications. Our staff are all Zend Certified university educated and experts at object oriented programming. While Worx International Inc. can handle any project from trouble shooting programs written by others all the way to finished mission-critical applications, we specialize in taking projects from inception all the way through to implementation - on budget, and on time. If you need help with your projects, we're the team to get it done right at a reasonable price.
-Over the years, there have been a number of tools that have been constant favorites in all of our projects. We have become the project administrators for most of these tools.
-Our developer tools are all Open Source. Here's a brief description:
-We're committed to PHP and to the Open Source community.
-Opportunities with Worx International Inc.:
-
The example file "test_mail.php" contents include:
-
-<?php
-
-include_once('../class.phpmailer.php');
-
-$mail = new PHPMailer();
-
-$body = $mail->getFile('contents.html');
-
-$body = eregi_replace("[\]",'',$body);
-$subject = eregi_replace("[\]",'',$subject);
-
-$mail->From = "name@yourdomain.com";
-$mail->FromName = "First Last";
-
-$mail->Subject = "PHPMailer Test Subject";
-
-$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
-
-$mail->MsgHTML($body);
-
-$mail->AddAddress("whoto@otherdomain.com", "John Doe");
-
-if(!$mail->Send()) {
- echo 'Failed to send mail';
-} else {
- echo 'Mail sent';
-}
-
-?>
-
-
-<body background="images/bkgrnd.gif" style="margin: 0px;">
-<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">
-<div align="center"><img src="images/phpmailer.gif" style="height: 90px; width: 340px"></div><br>
-<br>
- This is a test of PHPMailer v2.0.0 rc1.<br>
-<br>
-This particular example uses <strong>HTML</strong>, with a <div> tag and inline<br>
-styles.<br>
-<br>
-Also note the use of the PHPMailer at the top with no specific code to handle
-including it in the body of the email.</div>
-</body>
-
-Of course, you can still use PHPMailer the same way you have in the past. -That provides full compatibility with all existing scripts, while new scripts -can take advantage of the new features.
-Modify test_mail.php now with your own email address and try it out.
-To see what the email SHOULD look like in your HTML compatible email viewer: click here
-Authorise('pop3.example.com', 110, 30, 'mailer', 'password', 1);
-
- $mail = new PHPMailer();
-
- $mail->IsSMTP();
- $mail->SMTPDebug = 2;
- $mail->IsHTML(false);
-
- $mail->Host = 'relay.example.com';
-
- $mail->From = 'mailer@example.com';
- $mail->FromName = 'Example Mailer';
-
- $mail->Subject = 'My subject';
- $mail->Body = 'Hello world';
- $mail->AddAddress('name@anydomain.com', 'First Last');
-
- if (!$mail->Send())
- {
- echo $mail->ErrorInfo;
- }
-?>
-
-
-
-
diff --git a/examples/test1.php b/examples/test1.php
deleted file mode 100644
index 5e9a72fa..00000000
--- a/examples/test1.php
+++ /dev/null
@@ -1,29 +0,0 @@
-getFile('contents.html');
-
-$body = eregi_replace("[\]",'',$body);
-$subject = eregi_replace("[\]",'',$subject);
-
-$mail->From = "name@yourdomain.com";
-$mail->FromName = "First Last";
-
-$mail->Subject = "PHPMailer Test Subject";
-
-$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
-
-$mail->MsgHTML($body);
-
-$mail->AddAddress("whoto@otherdomain.com", "John Doe");
-
-if(!$mail->Send()) {
- echo 'Failed to send mail';
-} else {
- echo 'Mail sent';
-}
-
-?>
diff --git a/examples/test_db_smtp_basic.php b/examples/test_db_smtp_basic.php
new file mode 100644
index 00000000..85d01f8d
--- /dev/null
+++ b/examples/test_db_smtp_basic.php
@@ -0,0 +1,58 @@
+
+
+Here is a test HTML email
+ + diff --git a/test/phpmailer_test.php b/test/phpmailerTest.php similarity index 58% rename from test/phpmailer_test.php rename to test/phpmailerTest.php index 5ee74ec1..99581de1 100644 --- a/test/phpmailer_test.php +++ b/test/phpmailerTest.php @@ -1,20 +1,30 @@ TestCase( $name ); - } - /** * Run before each test is started. */ function setUp() { - global $global_vars; global $INCLUDE_DIR; + @include './testbootstrap.php'; //Overrides go in here + $this->Mail = new PHPMailer(); $this->Mail->Priority = 3; $this->Mail->Encoding = "8bit"; $this->Mail->CharSet = "iso-8859-1"; - $this->Mail->From = "unit_test@phpmailer.sf.net"; + if (array_key_exists('mail_from', $_REQUEST)) { + $this->Mail->From = $_REQUEST['mail_from']; + } else { + $this->Mail->From = 'unit_test@phpmailer.sf.net'; + } $this->Mail->FromName = "Unit Tester"; $this->Mail->Sender = ""; $this->Mail->Subject = "Unit Test"; $this->Mail->Body = ""; $this->Mail->AltBody = ""; $this->Mail->WordWrap = 0; - $this->Mail->Host = $global_vars["mail_host"]; + if (array_key_exists('mail_host', $_REQUEST)) { + $this->Mail->Host = $_REQUEST['mail_host']; + } else { + $this->Mail->Host = 'mail.example.com'; + } $this->Mail->Port = 25; $this->Mail->Helo = "localhost.localdomain"; $this->Mail->SMTPAuth = false; @@ -80,18 +91,19 @@ class phpmailerTest extends TestCase $this->Mail->AddReplyTo("no_reply@phpmailer.sf.net", "Reply Guy"); $this->Mail->Sender = "unit_test@phpmailer.sf.net"; - if(strlen($this->Mail->Host) > 0) + if(strlen($this->Mail->Host) > 0) { $this->Mail->Mailer = "smtp"; - else - { + } else { $this->Mail->Mailer = "mail"; $this->Sender = "unit_test@phpmailer.sf.net"; } - global $global_vars; - $this->SetAddress($global_vars["mail_to"], "Test User"); - if(strlen($global_vars["mail_cc"]) > 0) - $this->SetAddress($global_vars["mail_cc"], "Carbon User", "cc"); + 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'); + } } /** @@ -134,7 +146,7 @@ class phpmailerTest extends TestCase $ReportBody .= "---------------------" . $eol; $ReportBody .= "Unit Test Information" . $eol; $ReportBody .= "---------------------" . $eol; - $ReportBody .= "phpmailer version: " . $this->Mail->Version . $eol; + $ReportBody .= "phpmailer version: " . PHPMailer::VERSION . $eol; $ReportBody .= "Content Type: " . $this->Mail->ContentType . $eol; if(strlen($this->Mail->Host) > 0) @@ -146,11 +158,10 @@ class phpmailerTest extends TestCase { $ReportBody .= "Attachments:" . $eol; $ReportBody .= $bullet_start; - for($i = 0; $i < count($attachments); $i++) - { - $ReportBody .= $bullet . "Name: " . $attachments[$i][1] . ", "; - $ReportBody .= "Encoding: " . $attachments[$i][3] . ", "; - $ReportBody .= "Type: " . $attachments[$i][4] . $eol; + foreach($attachments as $attachment) { + $ReportBody .= $bullet . "Name: " . $attachment[1] . ", "; + $ReportBody .= "Encoding: " . $attachment[3] . ", "; + $ReportBody .= "Type: " . $attachment[4] . $eol; } $ReportBody .= $bullet_end . $eol; } @@ -271,7 +282,7 @@ class phpmailerTest extends TestCase $this->Mail->Subject .= ": Wordwrap"; $this->BuildBody(); - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); } /** @@ -286,7 +297,7 @@ class phpmailerTest extends TestCase $this->Mail->AddReplyTo("nobody@nobody.com", "Nobody (Unit Test)"); $this->BuildBody(); - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); } /** @@ -299,18 +310,18 @@ class phpmailerTest extends TestCase if(!$this->Mail->AddAttachment("test.png")) { - $this->assert(false, $this->Mail->ErrorInfo); + $this->assertTrue(false, $this->Mail->ErrorInfo); return; } - if(!$this->Mail->AddAttachment("phpmailer_test.php", "test.txt")) + if(!$this->Mail->AddAttachment(__FILE__, "test.txt")) { - $this->assert(false, $this->Mail->ErrorInfo); + $this->assertTrue(false, $this->Mail->ErrorInfo); return; } $this->BuildBody(); - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); } /** @@ -328,7 +339,7 @@ class phpmailerTest extends TestCase $this->Mail->AddStringAttachment($sAttachment, "string_attach.txt"); $this->BuildBody(); - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); } /** @@ -341,7 +352,13 @@ class phpmailerTest extends TestCase $this->Mail->Encoding = "quoted-printable"; $this->BuildBody(); - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); + + //Check that a quoted printable encode and decode results in the same as went in + $t = substr(file_get_contents(__FILE__), 0, 1024); //Just pick a chunk of this file as test content + $this->assertEquals($t, quoted_printable_decode($this->Mail->EncodeQP($t)), 'QP encoding round-trip failed'); + //$this->assertEquals($t, quoted_printable_decode($this->Mail->EncodeQPphp($t)), 'Native PHP QP encoding round-trip failed'); //TODO the PHP qp encoder is quite broken + } /** @@ -358,7 +375,7 @@ class phpmailerTest extends TestCase "phpmailer. Thank you!"; $this->BuildBody(); - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); } /** @@ -370,14 +387,14 @@ class phpmailerTest extends TestCase $this->Mail->Subject .= ": HTML + Attachment"; $this->Mail->IsHTML(true); - if(!$this->Mail->AddAttachment("phpmailer_test.php", "test_attach.txt")) + if(!$this->Mail->AddAttachment(__FILE__, "test_attach.txt")) { - $this->assert(false, $this->Mail->ErrorInfo); + $this->assertTrue(false, $this->Mail->ErrorInfo); return; } $this->BuildBody(); - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); } /** @@ -393,12 +410,16 @@ class phpmailerTest extends TestCase if(!$this->Mail->AddEmbeddedImage("test.png", "my-attach", "test.png", "base64", "image/png")) { - $this->assert(false, $this->Mail->ErrorInfo); + $this->assertTrue(false, $this->Mail->ErrorInfo); return; } $this->BuildBody(); - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); + //For code coverage + $this->Mail->AddEmbeddedImage('thisfiledoesntexist', 'xyz'); //Non-existent file + $this->Mail->AddEmbeddedImage(__FILE__, '123'); //Missing name + } /** @@ -414,18 +435,18 @@ class phpmailerTest extends TestCase if(!$this->Mail->AddEmbeddedImage("test.png", "my-attach", "test.png", "base64", "image/png")) { - $this->assert(false, $this->Mail->ErrorInfo); + $this->assertTrue(false, $this->Mail->ErrorInfo); return; } - if(!$this->Mail->AddAttachment("phpmailer_test.php", "test.txt")) + if(!$this->Mail->AddAttachment(__FILE__, "test.txt")) { - $this->assert(false, $this->Mail->ErrorInfo); + $this->assertTrue(false, $this->Mail->ErrorInfo); return; } $this->BuildBody(); - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); } /** @@ -442,7 +463,7 @@ class phpmailerTest extends TestCase $this->Mail->Subject .= ": AltBody + Word Wrap"; $this->BuildBody(); - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); } /** @@ -455,18 +476,18 @@ class phpmailerTest extends TestCase $this->Mail->Subject .= ": AltBody + Attachment"; $this->Mail->IsHTML(true); - if(!$this->Mail->AddAttachment("phpmailer_test.php", "test_attach.txt")) + if(!$this->Mail->AddAttachment(__FILE__, "test_attach.txt")) { - $this->assert(false, $this->Mail->ErrorInfo); + $this->assertTrue(false, $this->Mail->ErrorInfo); return; } $this->BuildBody(); - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); if (is_writable('.')) { file_put_contents('message.txt', $this->Mail->CreateHeader() . $this->Mail->CreateBody()); } else { - $this->assert(false, 'Could not write local file - check permissions'); + $this->assertTrue(false, 'Could not write local file - check permissions'); } } @@ -476,10 +497,30 @@ class phpmailerTest extends TestCase $subject = $this->Mail->Subject; $this->Mail->Subject = $subject . ": SMTP 1"; - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); $this->Mail->Subject = $subject . ": SMTP 2"; - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); + } + + function test_SendmailSend() { + $this->Mail->Body = "Sending via sendmail"; + $this->BuildBody(); + $subject = $this->Mail->Subject; + + $this->Mail->Subject = $subject . ": sendmail"; + $this->Mail->IsSendmail(); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); + } + + function test_MailSend() { + $this->Mail->Body = "Sending via mail()"; + $this->BuildBody(); + $subject = $this->Mail->Subject; + + $this->Mail->Subject = $subject . ": mail()"; + $this->Mail->IsMail(); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); } function test_SmtpKeepAlive() { @@ -489,10 +530,10 @@ class phpmailerTest extends TestCase $this->Mail->SMTPKeepAlive = true; $this->Mail->Subject = $subject . ": SMTP keep-alive 1"; - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); $this->Mail->Subject = $subject . ": SMTP keep-alive 2"; - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); $this->Mail->SmtpClose(); } @@ -505,124 +546,114 @@ class phpmailerTest extends TestCase $this->BuildBody(); $this->Mail->Subject = str_repeat("A", 998); - $this->assert($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); } - function test_Error() { - $this->Mail->Subject .= ": This should be sent"; - $this->BuildBody(); - $this->Mail->ClearAllRecipients(); // no addresses should cause an error - $this->assert($this->Mail->IsError() == false, "Error found"); - $this->assert($this->Mail->Send() == false, "Send succeeded"); - $this->assert($this->Mail->IsError(), "No error found"); - //Note that this is language dependent - $this->assertEquals('You must provide at least one recipient email address.', $this->Mail->ErrorInfo); - $this->Mail->AddAddress(get("mail_to")); - $this->assert($this->Mail->Send(), "Send failed"); - } - - function test_Addressing() { - $this->assert($this->Mail->AddAddress('a@example.com'), 'Addressing failed'); - $this->assert(!$this->Mail->AddAddress('a@example.com'), 'Duplicate addressing failed'); - $this->assert($this->Mail->AddCC('b@example.com'), 'CC addressing failed'); - $this->assert(!$this->Mail->AddCC('b@example.com'), 'CC duplicate Addressing failed'); - $this->assert(!$this->Mail->AddCC('a@example.com'), 'CC duplicate Addressing failed (2)'); - $this->assert($this->Mail->AddBCC('c@example.com'), 'BCC addressing failed'); - $this->assert(!$this->Mail->AddBCC('c@example.com'), 'BCC duplicate addressing failed'); - $this->assert(!$this->Mail->AddBCC('a@example.com'), 'BCC duplicate Addressing failed (2)'); - $this->Mail->ClearAddresses(); - $this->assert($this->Mail->AddAddress('a@example.com'), 'Addressing after clear failed'); - $this->Mail->ClearCCs(); - $this->assert($this->Mail->AddAddress('b@example.com'), 'CC addressing after clear failed'); - $this->Mail->ClearBCCs(); - $this->assert($this->Mail->AddAddress('c@example.com'), 'BCC addressing after clear failed'); - $this->Mail->AddAddress('a@example.com'); - $this->Mail->AddCC('b@example.com'); - $this->Mail->AddBCC('c@example.com'); - $this->Mail->ClearAllRecipients(); //Not much of a test, but helps coverage - } - - // Check that we are not missing any translations in any langauges - function test_Translations() { - //Extend this array as new strings are added - $expectedtranslations = array( - 'provide_address', - 'mailer_not_supported', - 'execute', - 'instantiate', - 'authenticate', - 'from_failed', - 'recipients_failed', - 'data_not_accepted', - 'connect_host', - 'file_access', - 'file_open', - 'encoding', - 'signing', - 'smtp_error' - ); - try { - foreach (new DirectoryIterator('../language') as $langfile) { - if (!preg_match('/^phpmailer\.lang-/', $langfile)) continue; //Skip non-language files - $PHPMAILER_LANG = array(); - include '../language/'.$langfile; - foreach($expectedtranslations as $string) { - $this->assert(isset($PHPMAILER_LANG[$string]), 'Translation missing; \''.$string.'\' in '.$langfile); - } - } - } - catch(Exception $e) { - $this->assert(false, 'No language files found!'); - } - } - - //Check that getFile works - function test_getFile() { - $a = $this->Mail->getFile('../class.phpmailer.php'); //Point at any non-empty file - $this->assert(($a !== false), 'GetFile failed to read a file.'); - } -} -/** - * Create and run test instance. - */ + function test_Error() { + $this->Mail->Subject .= ": This should be sent"; + $this->BuildBody(); + $this->Mail->ClearAllRecipients(); // no addresses should cause an error + $this->assertTrue($this->Mail->IsError() == false, "Error found"); + $this->assertTrue($this->Mail->Send() == false, "Send succeeded"); + $this->assertTrue($this->Mail->IsError(), "No error found"); + $this->assertEquals('You must provide at least one recipient email address.', $this->Mail->ErrorInfo); + $this->Mail->AddAddress($_REQUEST['mail_to']); + $this->assertTrue($this->Mail->Send(), "Send failed"); + } + + function test_Addressing() { + $this->assertFalse($this->Mail->AddAddress('a@example..com'), 'Invalid address accepted'); + $this->assertTrue($this->Mail->AddAddress('a@example.com'), 'Addressing failed'); + $this->assertFalse($this->Mail->AddAddress('a@example.com'), 'Duplicate addressing failed'); + $this->assertTrue($this->Mail->AddCC('b@example.com'), 'CC addressing failed'); + $this->assertFalse($this->Mail->AddCC('b@example.com'), 'CC duplicate addressing failed'); + $this->assertFalse($this->Mail->AddCC('a@example.com'), 'CC duplicate addressing failed (2)'); + $this->assertTrue($this->Mail->AddBCC('c@example.com'), 'BCC addressing failed'); + $this->assertFalse($this->Mail->AddBCC('c@example.com'), 'BCC duplicate addressing failed'); + $this->assertFalse($this->Mail->AddBCC('a@example.com'), 'BCC duplicate addressing failed (2)'); + $this->assertTrue($this->Mail->AddReplyTo('a@example.com'), 'Replyto Addressing failed'); + $this->assertFalse($this->Mail->AddReplyTo('a@example..com'), 'Invalid Replyto address accepted'); + $this->Mail->ClearAddresses(); + $this->Mail->ClearCCs(); + $this->Mail->ClearBCCs(); + $this->Mail->ClearReplyTos(); + } + + /** + * Test language files for missing and excess translations + * All languages are compared with English + */ + function test_Translations() { + $this->Mail->SetLanguage('en'); + $definedStrings = $this->Mail->GetTranslations(); + foreach (new DirectoryIterator('../language') as $fileInfo) { + if($fileInfo->isDot()) continue; + $matches = array(); + //Only look at language files, ignore anything else in there + if (preg_match('/^phpmailer\.lang-([a-z_]{2,})\.php$/', $fileInfo->getFilename(), $matches)) { + $lang = $matches[1]; //Extract language code + $PHPMAILER_LANG = array(); //Language strings get put in here + include $fileInfo->getPathname(); //Get language strings + $missing = array_diff(array_keys($definedStrings), array_keys($PHPMAILER_LANG)); + $extra = array_diff(array_keys($PHPMAILER_LANG), array_keys($definedStrings)); + $this->assertTrue(empty($missing), "Missing translations in $lang: ". implode(', ', $missing)); + $this->assertTrue(empty($extra), "Extra translations in $lang: ". implode(', ', $extra)); + } + } + } + + /** + * Encoding tests + */ + function test_Encodings() { + $this->Mail->Charset = 'iso-8859-1'; + $this->assertEquals('=A1Hola!_Se=F1or!', $this->Mail->EncodeQ('¡Hola! Señor!', 'text'), 'Q Encoding (text) failed'); + $this->assertEquals('=A1Hola!_Se=F1or!', $this->Mail->EncodeQ('¡Hola! Señor!', 'comment'), 'Q Encoding (comment) failed'); + $this->assertEquals('=A1Hola!_Se=F1or!', $this->Mail->EncodeQ('¡Hola! Señor!', 'phrase'), 'Q Encoding (phrase) failed'); + } + + /** + * Signing tests + */ + function test_Signing() { + $this->Mail->Sign('certfile.txt', 'keyfile.txt', 'password'); //TODO this is not really testing signing, but at least helps coverage + } + + /** + * Miscellaneous calls to improve test coverage and some small tests + */ + function test_Miscellaneous() { + $this->assertEquals('application/pdf', PHPMailer::_mime_types('pdf') , 'MIME TYPE lookup failed'); + $this->Mail->AddCustomHeader('SomeHeader: Some Value'); + $this->Mail->ClearCustomHeaders(); + $this->Mail->ClearAttachments(); + $this->Mail->IsHTML(false); + $this->Mail->IsSMTP(); + $this->Mail->IsMail(); + $this->Mail->IsSendMail(); + $this->Mail->IsQmail(); + $this->Mail->SetLanguage('fr'); + $this->Mail->Sender = ''; + $this->Mail->CreateHeader(); + $this->assertFalse($this->Mail->set('x', 'y'), 'Invalid property set succeeded'); + $this->assertTrue($this->Mail->set('Timeout', 11), 'Valid property set failed'); + $this->Mail->getFile(__FILE__); + } +} -if(isset($HTTP_GET_VARS)) - $global_vars = $HTTP_GET_VARS; -else - $global_vars = $_REQUEST; - -if(isset($global_vars["submitted"])) -{ - echo "Test results: