diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000..21b6b0fa3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+docs/phpdoc/
+test/message.txt
+test/testbootstrap.php
diff --git a/README.md b/README.md
index ac4551688..beae2848d 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,8 @@
-# PHPMailer - Full Featured Email Transfer Class for PHP
+# PHPMailer - A full-featured email creation and transfer class for PHP
## License
-This software is licenced under the LGPL. Please read LICENSE for information on the
+This software is licenced under the [LGPL](http://www.gnu.org/licenses/lgpl-2.1.html). Please read LICENSE for information on the
software availability and distribution.
## Class Features:
@@ -14,216 +14,95 @@ software availability and distribution.
- Uses the same methods as the very popular AspEmail active server (COM) component
- SMTP authentication
- Native language support
-- Word wrap, and more!
+- Word wrap
+- Compatible with PHP 5.0 and later
+- Much more!
## Why you might need it:
-Many PHP developers utilize email in their code. The only PHP function
-that supports this is the mail() function. However, it does not expose
-any of the popular features that many email clients use nowadays like
-HTML-based emails and attachments. There are two proprietary
-development tools out there that have all the functionality built into
-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.
-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
-projects.
+Many PHP developers utilize email in their code. The only PHP function that supports this is the mail() function. However, it does not provide any assistance for making use of popular features such as HTML-based emails and attachments.
+
+Formatting email correctly is surprisingly difficult. There are myriad overlapping RFCs, requiring tight adherence to horribly complicated formatting and encoding rules - the vast majority of code that you'll find online that uses the mail() function directly is just plain wrong!
+*Please* don't be tempted to do it yourself - if you don't use PHPMailer, there are many other excellent libraries that you should look at before rolling your own - try SwiftMailer, Zend_Mail, eZcomponents etc.
+
+The PHP mail() function usually sends via a local mail server, typically fronted by a `sendmail` binary on Linux, BSD and OS X platforms, however, Windows usually doesn't include a local mail server; PHPMailer's integrated SMTP implementation allows email sending on Windows platforms without a local mail server.
## Installation:
-Copy class.phpmailer.php into your php.ini include_path. If you are
-using the SMTP mailer then place class.smtp.php in your path as well.
-In the language directory you will find several files like
-phpmailer.lang-en.php. If you look right before the .php extension
-that there are two letters. These represent the language type of the
-translation file. For instance "en" is the English file and "br" is
-the Portuguese file. Choose the file that best fits with your language
-and place it in the PHP include path. If your language is English
-then you have nothing more to do. If it is a different language then
-you must point PHPMailer to the correct translation. To do this, call
-the PHPMailer SetLanguage method like so:
+Copy the contents of the PHPMailer folder into somewhere that's in your PHP include_path setting.
+
+## Localization
+PHPMailer defaults to English, but in the `languages` folder you'll find numerous translations for PHPMailer error messages that you may encounter. Their filenames contain [ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) language code for the translations, for example `fr` for French. To specify a language, you need to tell PHPMailer which one to use, like this:
```php
-// To load the Portuguese version
-$mail->SetLanguage("br", "/optional/path/to/language/directory/");
+// To load the French version
+$mail->SetLanguage('fr', '/optional/path/to/language/directory/');
```
-That's it. You should now be ready to use PHPMailer!
-
-## A Simple Example:
+## A Simple Example
```php
IsSMTP(); // set mailer to use SMTP
-$mail->Host = "smtp1.example.com;smtp2.example.com"; // specify main and backup server
-$mail->SMTPAuth = true; // turn on SMTP authentication
-$mail->Username = "jswan"; // SMTP username
-$mail->Password = "secret"; // SMTP password
-
-$mail->From = "from@example.com";
-$mail->FromName = "Mailer";
-$mail->AddAddress("josh@example.net", "Josh Adams");
-$mail->AddAddress("ellen@example.com"); // name is optional
-$mail->AddReplyTo("info@example.com", "Information");
-
-$mail->WordWrap = 50; // set word wrap to 50 characters
-$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
-$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
-$mail->IsHTML(true); // set email format to HTML
-
-$mail->Subject = "Here is the subject";
-$mail->Body = "This is the HTML message body in bold!";
-$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
-
-if(!$mail->Send())
-{
- echo "Message could not be sent.
";
- echo "Mailer Error: " . $mail->ErrorInfo;
+require 'class.phpmailer.php';
+
+$mail = new PHPMailer;
+
+$mail->IsSMTP(); // Set mailer to use SMTP
+$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server
+$mail->SMTPAuth = true; // Enable SMTP authentication
+$mail->Username = 'jswan'; // SMTP username
+$mail->Password = 'secret'; // SMTP password
+
+$mail->From = 'from@example.com';
+$mail->FromName = 'Mailer';
+$mail->AddAddress('josh@example.net', 'Josh Adams'); // Add a recipient
+$mail->AddAddress('ellen@example.com'); // Name is optional
+$mail->AddReplyTo('info@example.com', 'Information');
+
+$mail->WordWrap = 50; // Set word wrap to 50 characters
+$mail->AddAttachment('/var/tmp/file.tar.gz'); // Add attachments
+$mail->AddAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
+$mail->IsHTML(true); // Set email format to HTML
+
+$mail->Subject = 'Here is the subject';
+$mail->Body = 'This is the HTML message body in bold!';
+$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
+
+if(!$mail->Send()) {
+ echo 'Message could not be sent.';
+ echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
-echo "Message has been sent";
-?>
+echo 'Message has been sent';
```
-## CHANGELOG
-
-See ChangeLog.txt
-
-Download: http://sourceforge.net/project/showfiles.php?group_id=26031
-
-Andy Prevost
-
-## History (see changelog.txt for more)
-
-Version 5.2.1 (January 16, 2012)
-
-Patch release (see changelog.txt).
-
-Version 5.2.0 (July 19, 2011)
-
-With the release of this version, PHPMailer has moved to Apache
-Extras:
- http://code.google.com/a/apache-extras.org/p/phpmailer/
-
-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
-the http://phpmailer.codeworxtech.com website.
-
-The phpunit.php has been updated to support PHP5.
-
-For all other changes and notes, please see the changelog.
-
-Donations are accepted at PayPal with our id "paypal@worxteam.com".
-
-Version 2.2 (July 15 2008)
-
-- see the changelog.
-
-Version 2.1 (June 04 2008)
-
-With this release, we are announcing that the development of PHPMailer for PHP5
-will be our focus from this date on. We have implemented all the enhancements
-and fixes from the latest release of PHPMailer for PHP4.
-
-Far more important, though, is that this release of PHPMailer (v2.1) is
-fully tested with E_STRICT error checking enabled.
-
-** NOTE: WE HAVE A NEW LANGUAGE VARIABLE FOR DIGITALLY SIGNED S/MIME EMAILS.
- IF YOU CAN HELP WITH LANGUAGES OTHER THAN ENGLISH AND SPANISH, IT WOULD BE
- APPRECIATED.
-
-We have now added S/MIME functionality (ability to digitally sign emails).
-BIG THANKS TO "sergiocambra" for posting this patch back in November 2007.
-The "Signed Emails" functionality adds the Sign method to pass the private key
-filename and the password to read it, and then email will be sent with
-content-type multipart/signed and with the digital signature attached.
-
-A quick note on E_STRICT:
-
-- In about half the test environments the development version was subjected
- to, an error was thrown for the date() functions (used at line 1565 and 1569).
- This is NOT a PHPMailer error, it is the result of an incorrectly configured
- PHP5 installation. The fix is to modify your 'php.ini' file and include the
- date.timezone = America/New York
- directive, (for your own server timezone)
-- If you do get this error, and are unable to access your php.ini file, there is
- a workaround. In your PHP script, add
- date_default_timezone_set('America/Toronto');
-
- * do NOT try to use
- $myVar = date_default_timezone_get();
- as a test, it will throw an error.
-
-We have also included more example files to show the use of "sendmail", "mail()",
-"smtp", and "gmail".
+You'll find plenty more to play with in the `examples` folder.
-We are also looking for more programmers to join the volunteer development team.
-If you have an interest in this, please let us know.
+That's it. You should now be ready to use PHPMailer!
-Enjoy!
+## Documentation
+You'll find some basic user-level docs in the docs folder, and you can generate complete API-level documentation using the `generatedocs.sh` shell script in the docs folder, though you'll need to install [PHPDocumentor](http://www.phpdoc.org) first.
-Version 2.1.0beta1 & beta2
+## Tests
-please note, this is BETA software
-** DO NOT USE THIS IN PRODUCTION OR LIVE PROJECTS
-INTENDED STRICTLY FOR TESTING
+You'll find a PHPUnit test script in the `test` folder.
-** NOTE:
+## Contributing
-As of November 2007, PHPMailer has a new project team headed by industry
-veteran Andy Prevost (codeworxtech). The first release in more than two
-years will focus on fixes, adding ease-of-use enhancements, provide
-basic compatibility with PHP4 and PHP5 using PHP5 backwards compatibility
-features. A new release is planned before year-end 2007 that will provide
-full compatiblity with PHP4 and PHP5, as well as more bug fixes.
+Please submit bug reports, suggestions and pull requests to the [Google Code tracker](https://code.google.com/a/apache-extras.org/p/phpmailer/issues/list) or the [GitHub issue tracker](https://github.com/Synchro/PHPMailer/issues).
-We are looking for project developers to assist in restoring PHPMailer to
-its leadership position. Our goals are to simplify use of PHPMailer, provide
-good documentation and examples, and retain backward compatibility to level
-1.7.3 standards.
+We're particularly interested in fixes for edge-cases, expanding test coverage and updating translations.
-If you are interested in helping out, visit http://sourceforge.net/projects/phpmailer
-and indicate your interest.
+Please *don't* use the sourceforge project any more.
-**
+## Changelog
-## See also
+See changelog.txt
-http://phpmailer.sourceforge.net/
-http://code.google.com/a/apache-extras.org/p/phpmailer/
+## History
+PHPMailer was originally written in 2001 by Brent R. Matzelle as a [sourceforge project](http://sourceforge.net/projects/phpmailer/).
+Marcus Bointon (coolbru on SF) and Andy Prevost (codeworxtech) took over the project in 2004.
+The project became an [Apache incubator project on Google Code](https://code.google.com/a/apache-extras.org/p/phpmailer/) in 2010, managed by Jim Jagielski
+Marcus maintains a [GitHub repository](https://github.com/Synchro/PHPMailer) that's kept in sync with the Google Code project as far as is practical.
\ No newline at end of file
diff --git a/changelog.txt b/changelog.txt
index e2c982db4..789137a89 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,421 +1,472 @@
ChangeLog
-
+
NOTE: THIS VERSION OF PHPMAILER IS DESIGNED FOR PHP5/PHP6.
IT WILL NOT WORK WITH PHP4.
-
+
+Version 5.2.2-rc2 (November 6, 2012)
+ * Fix SMTP server rotation (Bugz: 118)
+ * Allow override of autogen'ed 'Date' header (for Drupal's
+ og_mailinglist module)
+ * No whitespace after '-f' option (Bugz: 116)
+ * Work around potential warning (Bugz: 114)
+
+Version 5.2.2-rc1 (September 28, 2012)
+ * Header encoding works with long lines (Bugz: 93)
+ * Turkish language update (Bugz: 94)
+ * undefined $pattern in EncodeQ bug squashed (Bugz: 98)
+ * use of mail() in safe_mode now works (Bugz: 96)
+ * ValidateAddress() now 'public static' so people can override the
+ default and use their own validation scheme.
+ * ValidateAddress() no longer uses broken FILTER_VALIDATE_EMAIL
+ * Added in AUTH PLAIN SMTP authentication
+
+Version 5.2.2-beta2 (August 17, 2012)
+ * Fixed Postfix VERP support (Bugz: 92)
+ * Allow action_function callbacks to pass/use
+ the From address (passed as final param)
+ * Prevent inf look for get_lines() (Bugz: 77)
+ * New public var ($UseSendmailOptions). Only pass sendmail()
+ options iff we really are using sendmail or something sendmail
+ compatible. (Bugz: 75)
+ * default setting for LE returned to "\n" due to popular demand.
+
+Version 5.2.2-beta1 (July 13, 2012)
+ * Expose PreSend() and PostSend() as public methods to allow
+ for more control if serializing message sending.
+ * GetSentMIMEMessage() only constructs the message copy when
+ needed. Save memory.
+ * Only pass params to mail() if the underlying MTA is
+ "sendmail" (as defined as "having the string sendmail
+ in its pathname") [#69]
+ * Attachments now work with Amazon SES and others [Bugz#70]
+ * Debug output now sent to stdout (via echo) or error_log [Bugz#5]
+ * New var: Debugoutput (for above) [Bugz#5]
+ * SMTP reads now Timeout aware (new var: Timeout=15) [Bugz#71]
+ * SMTP reads now can have a Timelimit associated with them
+ (new var: Timelimit=30)[Bugz#71]
+ * Fix quoting issue associated with charsets
+ * default setting for LE is now RFC compliant: "\r\n"
+ * Return-Path can now be user defined (new var: ReturnPath)
+ (the default is "" which implies no change from previous
+ behavior, which was to use either From or Sender) [Bugz#46]
+ * X-Mailer header can now be disabled (by setting to a
+ whitespace string, eg " ") [Bugz#66]
+ * Bugz closed: #68, #60, #42, #43, #59, #55, #66, #48, #49,
+ #52, #31, #41, #5. #70, #69
+
Version 5.2.1 (January 16, 2012)
-* Closed several bugs
-* Performance improvements
-* MsgHTML() now returns the message as required.
-* New method: GetSentMIMEMessage() (returns full copy of sent message)
-
+ * Closed several bugs#5
+ * Performance improvements
+ * MsgHTML() now returns the message as required.
+ * New method: GetSentMIMEMessage() (returns full copy of sent message)
+
Version 5.2 (July 19, 2011)
-* protected MIME body and header
-* better DKIM DNS Resource Record support
-* better aly handling
-* htmlfilter class added to extras
-* moved to Apache Extras
-
+ * protected MIME body and header
+ * better DKIM DNS Resource Record support
+ * better aly handling
+ * htmlfilter class added to extras
+ * moved to Apache Extras
+
Version 5.1 (October 20, 2009)
-* fixed filename issue with AddStringAttachment (thanks to Tony)
-* fixed "SingleTo" property, now works with Senmail, Qmail, and SMTP in
- addition to PHP mail()
-* added DKIM digital signing functionality
- New properties:
- - DKIM_domain (sets the domain name)
- - DKIM_private (holds DKIM private key)
- - DKIM_passphrase (holds your DKIM passphrase)
- - DKIM_selector (holds the DKIM "selector")
- - DKIM_identity (holds the identifying email address)
-* added callback function support
- - callback function parameters include:
- result, to, cc, bcc, subject and body
- * see the test/test_callback.php file for usage.
-* added "auto" identity functionality
- - can automatically add:
- - Return-path (if Sender not set)
- - Reply-To (if ReplyTo not set)
- - can be disabled:
- - $mail->SetFrom('yourname@yourdomain.com','First Last',false);
- - or by adding the $mail->Sender and/or $mail->ReplyTo properties
- Note: "auto" identity added to help with emails ending up in spam
- or junk boxes because of missing headers
-
+ * fixed filename issue with AddStringAttachment (thanks to Tony)
+ * fixed "SingleTo" property, now works with Senmail, Qmail, and SMTP in
+ addition to PHP mail()
+ * added DKIM digital signing functionality
+ New properties:
+ - DKIM_domain (sets the domain name)
+ - DKIM_private (holds DKIM private key)
+ - DKIM_passphrase (holds your DKIM passphrase)
+ - DKIM_selector (holds the DKIM "selector")
+ - DKIM_identity (holds the identifying email address)
+ * added callback function support
+ - callback function parameters include:
+ result, to, cc, bcc, subject and body
+ * see the test/test_callback.php file for usage.
+ * added "auto" identity functionality
+ - can automatically add:
+ - Return-path (if Sender not set)
+ - Reply-To (if ReplyTo not set)
+ - can be disabled:
+ - $mail->SetFrom('yourname@yourdomain.com','First Last',false);
+ - or by adding the $mail->Sender and/or $mail->ReplyTo properties
+ Note: "auto" identity added to help with emails ending up in spam
+ or junk boxes because of missing headers
+
Version 5.0.2 (May 24, 2009)
-* Fix for missing attachments when inline graphics are present
-* Fix for missing Cc in header when using SMTP (mail was sent,
- but not displayed in header -- Cc receiver only saw email To:
- line and no Cc line, but did get the email (To receiver
- saw same)
-
+ * Fix for missing attachments when inline graphics are present
+ * Fix for missing Cc in header when using SMTP (mail was sent,
+ but not displayed in header -- Cc receiver only saw email To:
+ line and no Cc line, but did get the email (To receiver
+ saw same)
+
Version 5.0.1 (April 05, 2009)
-* Temporary fix for missing attachments
-
+ * Temporary fix for missing attachments
+
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/
-
+
+ * 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)
-
-* added Arabic language (many thanks to Bahjat Al Mostafa)
-* removed English language from language files and made it a default within
- class.phpmailer.php - if no language is found, it will default to use
- the english language translation
-* fixed public/private declarations
-* corrected line 1728, $basedir to $directory
-* added $sign_cert_file to avoid improper duplicate use of $sign_key_file
-* corrected $this->Hello on line 612 to $this->Helo
-* changed default of $LE to "\r\n" to comply with RFC 2822. Can be set by the user
- if default is not acceptable
-* removed trim() from return results in EncodeQP
-* /test and three files it contained are removed from version 2.3
-* fixed phpunit.php for compliance with PHP5
-* changed $this->AltBody = $textMsg; to $this->AltBody = html_entity_decode($textMsg);
-* We have removed the /phpdoc from the downloads. All documentation is now on
- the http://phpmailer.codeworxtech.com website.
-
+
+ * added Arabic language (many thanks to Bahjat Al Mostafa)
+ * removed English language from language files and made it a default within
+ class.phpmailer.php - if no language is found, it will default to use
+ the english language translation
+ * fixed public/private declarations
+ * corrected line 1728, $basedir to $directory
+ * added $sign_cert_file to avoid improper duplicate use of $sign_key_file
+ * corrected $this->Hello on line 612 to $this->Helo
+ * changed default of $LE to "\r\n" to comply with RFC 2822. Can be set by the user
+ if default is not acceptable
+ * removed trim() from return results in EncodeQP
+ * /test and three files it contained are removed from version 2.3
+ * fixed phpunit.php for compliance with PHP5
+ * changed $this->AltBody = $textMsg; to $this->AltBody = html_entity_decode($textMsg);
+ * We have removed the /phpdoc from the downloads. All documentation is now on
+ the http://phpmailer.codeworxtech.com website.
+
Version 2.2.1 () July 19 2008
-
-* fixed line 1092 in class.smtp.php (my apologies, error on my part)
-
+
+ * fixed line 1092 in class.smtp.php (my apologies, error on my part)
+
Version 2.2 () July 15 2008
-
-* Fixed redirect issue (display of UTF-8 in thank you redirect)
-* fixed error in getResponse function declaration (class.pop3.php)
-* PHPMailer now PHP6 compliant
-* fixed line 1092 in class.smtp.php (endless loop from missing = sign)
-
+
+ * Fixed redirect issue (display of UTF-8 in thank you redirect)
+ * fixed error in getResponse function declaration (class.pop3.php)
+ * PHPMailer now PHP6 compliant
+ * fixed line 1092 in class.smtp.php (endless loop from missing = sign)
+
Version 2.1 (Wed, June 04 2008)
-
-** NOTE: WE HAVE A NEW LANGUAGE VARIABLE FOR DIGITALLY SIGNED S/MIME EMAILS.
- IF YOU CAN HELP WITH LANGUAGES OTHER THAN ENGLISH AND SPANISH, IT WOULD BE
- APPRECIATED.
-
-* added S/MIME functionality (ability to digitally sign emails)
- BIG THANKS TO "sergiocambra" for posting this patch back in November 2007.
- The "Signed Emails" functionality adds the Sign method to pass the private key
- filename and the password to read it, and then email will be sent with
- content-type multipart/signed and with the digital signature attached.
-* fully compatible with E_STRICT error level
- - Please note:
- In about half the test environments this development version was subjected
- to, an error was thrown for the date() functions used (line 1565 and 1569).
- This is NOT a PHPMailer error, it is the result of an incorrectly configured
- PHP5 installation. The fix is to modify your 'php.ini' file and include the
- date.timezone = America/New York
- directive, to your own server timezone
- - If you do get this error, and are unable to access your php.ini file:
- In your PHP script, add
- date_default_timezone_set('America/Toronto');
- - do not try to use
- $myVar = date_default_timezone_get();
- as a test, it will throw an error.
-* added ability to define path (mainly for embedded images)
- function MsgHTML($message,$basedir='') ... where:
- $basedir is the fully qualified path
-* fixed MsgHTML() function:
- - Embedded Images where images are specified by :// will not be altered or embedded
-* fixed the return value of SMTP exit code ( pclose )
-* addressed issue of multibyte characters in subject line and truncating
-* added ability to have user specified Message ID
- (default is still that PHPMailer create a unique Message ID)
-* corrected unidentified message type to 'application/octet-stream'
-* fixed chunk_split() multibyte issue (thanks to Colin Brown, et al).
-* added check for added attachments
-* enhanced conversion of HTML to text in MsgHTML (thanks to "brunny")
-
+
+ ** NOTE: WE HAVE A NEW LANGUAGE VARIABLE FOR DIGITALLY SIGNED S/MIME EMAILS.
+ IF YOU CAN HELP WITH LANGUAGES OTHER THAN ENGLISH AND SPANISH, IT WOULD BE
+ APPRECIATED.
+
+ * added S/MIME functionality (ability to digitally sign emails)
+ BIG THANKS TO "sergiocambra" for posting this patch back in November 2007.
+ The "Signed Emails" functionality adds the Sign method to pass the private key
+ filename and the password to read it, and then email will be sent with
+ content-type multipart/signed and with the digital signature attached.
+ * fully compatible with E_STRICT error level
+ - Please note:
+ In about half the test environments this development version was subjected
+ to, an error was thrown for the date() functions used (line 1565 and 1569).
+ This is NOT a PHPMailer error, it is the result of an incorrectly configured
+ PHP5 installation. The fix is to modify your 'php.ini' file and include the
+ date.timezone = America/New York
+ directive, to your own server timezone
+ - If you do get this error, and are unable to access your php.ini file:
+ In your PHP script, add
+ date_default_timezone_set('America/Toronto');
+ - do not try to use
+ $myVar = date_default_timezone_get();
+ as a test, it will throw an error.
+ * added ability to define path (mainly for embedded images)
+ function MsgHTML($message,$basedir='') ... where:
+ $basedir is the fully qualified path
+ * fixed MsgHTML() function:
+ - Embedded Images where images are specified by :// will not be altered or embedded
+ * fixed the return value of SMTP exit code ( pclose )
+ * addressed issue of multibyte characters in subject line and truncating
+ * added ability to have user specified Message ID
+ (default is still that PHPMailer create a unique Message ID)
+ * corrected unidentified message type to 'application/octet-stream'
+ * fixed chunk_split() multibyte issue (thanks to Colin Brown, et al).
+ * added check for added attachments
+ * enhanced conversion of HTML to text in MsgHTML (thanks to "brunny")
+
Version 2.1.0beta2 (Sun, Dec 02 2007)
-* implemented updated EncodeQP (thanks to coolbru, aka Marcus Bointon)
-* finished all testing, all known bugs corrected, enhancements tested
-- note: will NOT work with PHP4.
-
-please note, this is BETA software
-** DO NOT USE THIS IN PRODUCTION OR LIVE PROJECTS
-INTENDED STRICTLY FOR TESTING
-
+ * implemented updated EncodeQP (thanks to coolbru, aka Marcus Bointon)
+ * finished all testing, all known bugs corrected, enhancements tested
+ - note: will NOT work with PHP4.
+
+ please note, this is BETA software
+ ** DO NOT USE THIS IN PRODUCTION OR LIVE PROJECTS
+ INTENDED STRICTLY FOR TESTING
+
Version 2.1.0beta1
-please note, this is BETA software
-** DO NOT USE THIS IN PRODUCTION OR LIVE PROJECTS
-INTENDED STRICTLY FOR TESTING
-
+ please note, this is BETA software
+ ** DO NOT USE THIS IN PRODUCTION OR LIVE PROJECTS
+ INTENDED STRICTLY FOR TESTING
+
Version 2.0.0 rc2 (Fri, Nov 16 2007), interim release
-* implements new property to control VERP in class.smtp.php
- example (requires instantiating class.smtp.php):
- $mail->do_verp = true;
-* POP-before-SMTP functionality included, thanks to Richard Davey
- (see class.pop3.php & pop3_before_smtp_test.php for examples)
-* included example showing how to use PHPMailer with GMAIL
-* fixed the missing Cc in SendMail() and Mail()
-
-******************
-A note on sending bulk emails:
-
-If the email you are sending is not personalized, consider using the
-"undisclosed-recipient:;" strategy. That is, put all of your recipients
-in the Bcc field and set the To field to "undisclosed-recipients:;".
-It's a lot faster (only one send) and saves quite a bit on resources.
-Contrary to some opinions, this will not get you listed in spam engines -
-it's a legitimate way for you to send emails.
-
-A partial example for use with PHPMailer:
-
-$mail->AddAddress("undisclosed-recipients:;");
-$mail->AddBCC("email1@anydomain.com,email2@anyotherdomain.com,email3@anyalternatedomain.com");
-
-Many email service providers restrict the number of emails that can be sent
-in any given time period. Often that is between 50 - 60 emails maximum
-per hour or per send session.
-
-If that's the case, then break up your Bcc lists into chunks that are one
-less than your limit, and put a pause in your script.
-*******************
-
+ * implements new property to control VERP in class.smtp.php
+ example (requires instantiating class.smtp.php):
+ $mail->do_verp = true;
+ * POP-before-SMTP functionality included, thanks to Richard Davey
+ (see class.pop3.php & pop3_before_smtp_test.php for examples)
+ * included example showing how to use PHPMailer with GMAIL
+ * fixed the missing Cc in SendMail() and Mail()
+
+ ******************
+ A note on sending bulk emails:
+
+ If the email you are sending is not personalized, consider using the
+ "undisclosed-recipient:;" strategy. That is, put all of your recipients
+ in the Bcc field and set the To field to "undisclosed-recipients:;".
+ It's a lot faster (only one send) and saves quite a bit on resources.
+ Contrary to some opinions, this will not get you listed in spam engines -
+ it's a legitimate way for you to send emails.
+
+ A partial example for use with PHPMailer:
+
+ $mail->AddAddress("undisclosed-recipients:;");
+ $mail->AddBCC("email1@anydomain.com,email2@anyotherdomain.com,email3@anyalternatedomain.com");
+
+ Many email service providers restrict the number of emails that can be sent
+ in any given time period. Often that is between 50 - 60 emails maximum
+ per hour or per send session.
+
+ If that's the case, then break up your Bcc lists into chunks that are one
+ less than your limit, and put a pause in your script.
+ *******************
+
Version 2.0.0 rc1 (Thu, Nov 08 2007), interim release
-* dramatically simplified using inline graphics ... it's fully automated and requires no user input
-* added automatic document type detection for attachments and pictures
-* added MsgHTML() function to replace Body tag for HTML emails
-* fixed the SendMail security issues (input validation vulnerability)
-* enhanced the AddAddresses functionality so that the "Name" portion is used in the email address
-* removed the need to use the AltBody method (set from the HTML, or default text used)
-* set the PHP Mail() function as the default (still support SendMail, SMTP Mail)
-* removed the need to set the IsHTML property (set automatically)
-* added Estonian language file by Indrek Päri
-* added header injection patch
-* added "set" method to permit users to create their own pseudo-properties like 'X-Headers', etc.
- example of use:
- $mail->set('X-Priority', '3');
- $mail->set('X-MSMail-Priority', 'Normal');
-* fixed warning message in SMTP get_lines method
-* added TLS/SSL SMTP support
- example of use:
- $mail = new PHPMailer();
- $mail->Mailer = "smtp";
- $mail->Host = "smtp.example.com";
- $mail->SMTPSecure = "tls"; // option
- //$mail->SMTPSecure = "ssl"; // option
- ...
- $mail->Send();
-* PHPMailer has been tested with PHP4 (4.4.7) and PHP5 (5.2.7)
-* Works with PHP installed as a module or as CGI-PHP
-- NOTE: will NOT work with PHP5 in E_STRICT error mode
-
+ * dramatically simplified using inline graphics ... it's fully automated and requires no user input
+ * added automatic document type detection for attachments and pictures
+ * added MsgHTML() function to replace Body tag for HTML emails
+ * fixed the SendMail security issues (input validation vulnerability)
+ * enhanced the AddAddresses functionality so that the "Name" portion is used in the email address
+ * removed the need to use the AltBody method (set from the HTML, or default text used)
+ * set the PHP Mail() function as the default (still support SendMail, SMTP Mail)
+ * removed the need to set the IsHTML property (set automatically)
+ * added Estonian language file by Indrek Päri
+ * added header injection patch
+ * added "set" method to permit users to create their own pseudo-properties like 'X-Headers', etc.
+ example of use:
+ $mail->set('X-Priority', '3');
+ $mail->set('X-MSMail-Priority', 'Normal');
+ * fixed warning message in SMTP get_lines method
+ * added TLS/SSL SMTP support
+ example of use:
+ $mail = new PHPMailer();
+ $mail->Mailer = "smtp";
+ $mail->Host = "smtp.example.com";
+ $mail->SMTPSecure = "tls"; // option
+ //$mail->SMTPSecure = "ssl"; // option
+ ...
+ $mail->Send();
+ * PHPMailer has been tested with PHP4 (4.4.7) and PHP5 (5.2.7)
+ * Works with PHP installed as a module or as CGI-PHP
+ - NOTE: will NOT work with PHP5 in E_STRICT error mode
+
Version 1.73 (Sun, Jun 10 2005)
-* Fixed denial of service bug: http://www.cybsec.com/vuln/PHPMailer-DOS.pdf
-* Now has a total of 20 translations
-* Fixed alt attachments bug: http://tinyurl.com/98u9k
-
+ * Fixed denial of service bug: http://www.cybsec.com/vuln/PHPMailer-DOS.pdf
+ * Now has a total of 20 translations
+ * Fixed alt attachments bug: http://tinyurl.com/98u9k
+
Version 1.72 (Wed, May 25 2004)
-* Added Dutch, Swedish, Czech, Norwegian, and Turkish translations.
-* Received: Removed this method because spam filter programs like
-SpamAssassin reject this header.
-* Fixed error count bug.
-* SetLanguage default is now "language/".
-* Fixed magic_quotes_runtime bug.
-
+ * Added Dutch, Swedish, Czech, Norwegian, and Turkish translations.
+ * Received: Removed this method because spam filter programs like
+ SpamAssassin reject this header.
+ * Fixed error count bug.
+ * SetLanguage default is now "language/".
+ * Fixed magic_quotes_runtime bug.
+
Version 1.71 (Tue, Jul 28 2003)
-* Made several speed enhancements
-* Added German and Italian translation files
-* Fixed HELO/AUTH bugs on keep-alive connects
-* Now provides an error message if language file does not load
-* Fixed attachment EOL bug
-* Updated some unclear documentation
-* Added additional tests and improved others
-
+ * Made several speed enhancements
+ * Added German and Italian translation files
+ * Fixed HELO/AUTH bugs on keep-alive connects
+ * Now provides an error message if language file does not load
+ * Fixed attachment EOL bug
+ * Updated some unclear documentation
+ * Added additional tests and improved others
+
Version 1.70 (Mon, Jun 20 2003)
-* Added SMTP keep-alive support
-* Added IsError method for error detection
-* Added error message translation support (SetLanguage)
-* Refactored many methods to increase library performance
-* Hello now sends the newer EHLO message before HELO as per RFC 2821
-* Removed the boundary class and replaced it with GetBoundary
-* Removed queue support methods
-* New $Hostname variable
-* New Message-ID header
-* Received header reformat
-* Helo variable default changed to $Hostname
-* Removed extra spaces in Content-Type definition (#667182)
-* Return-Path should be set to Sender when set
-* Adds Q or B encoding to headers when necessary
-* quoted-encoding should now encode NULs \000
-* Fixed encoding of body/AltBody (#553370)
-* Adds "To: undisclosed-recipients:;" when all recipients are hidden (BCC)
-* Multiple bug fixes
-
+ * Added SMTP keep-alive support
+ * Added IsError method for error detection
+ * Added error message translation support (SetLanguage)
+ * Refactored many methods to increase library performance
+ * Hello now sends the newer EHLO message before HELO as per RFC 2821
+ * Removed the boundary class and replaced it with GetBoundary
+ * Removed queue support methods
+ * New $Hostname variable
+ * New Message-ID header
+ * Received header reformat
+ * Helo variable default changed to $Hostname
+ * Removed extra spaces in Content-Type definition (#667182)
+ * Return-Path should be set to Sender when set
+ * Adds Q or B encoding to headers when necessary
+ * quoted-encoding should now encode NULs \000
+ * Fixed encoding of body/AltBody (#553370)
+ * Adds "To: undisclosed-recipients:;" when all recipients are hidden (BCC)
+ * Multiple bug fixes
+
Version 1.65 (Fri, Aug 09 2002)
-* Fixed non-visible attachment bug (#585097) for Outlook
-* SMTP connections are now closed after each transaction
-* Fixed SMTP::Expand return value
-* Converted SMTP class documentation to phpDocumentor format
-
+ * Fixed non-visible attachment bug (#585097) for Outlook
+ * SMTP connections are now closed after each transaction
+ * Fixed SMTP::Expand return value
+ * Converted SMTP class documentation to phpDocumentor format
+
Version 1.62 (Wed, Jun 26 2002)
-* Fixed multi-attach bug
-* Set proper word wrapping
-* Reduced memory use with attachments
-* Added more debugging
-* Changed documentation to phpDocumentor format
-
+ * Fixed multi-attach bug
+ * Set proper word wrapping
+ * Reduced memory use with attachments
+ * Added more debugging
+ * Changed documentation to phpDocumentor format
+
Version 1.60 (Sat, Mar 30 2002)
-* Sendmail pipe and address patch (Christian Holtje)
-* Added embedded image and read confirmation support (A. Ognio)
-* Added unit tests
-* Added SMTP timeout support (*nix only)
-* Added possibly temporary PluginDir variable for SMTP class
-* Added LE message line ending variable
-* Refactored boundary and attachment code
-* Eliminated SMTP class warnings
-* Added SendToQueue method for future queuing support
-
+ * Sendmail pipe and address patch (Christian Holtje)
+ * Added embedded image and read confirmation support (A. Ognio)
+ * Added unit tests
+ * Added SMTP timeout support (*nix only)
+ * Added possibly temporary PluginDir variable for SMTP class
+ * Added LE message line ending variable
+ * Refactored boundary and attachment code
+ * Eliminated SMTP class warnings
+ * Added SendToQueue method for future queuing support
+
Version 1.54 (Wed, Dec 19 2001)
-* Add some queuing support code
-* Fixed a pesky multi/alt bug
-* Messages are no longer forced to have "To" addresses
-
+ * Add some queuing support code
+ * Fixed a pesky multi/alt bug
+ * Messages are no longer forced to have "To" addresses
+
Version 1.50 (Thu, Nov 08 2001)
-* Fix extra lines when not using SMTP mailer
-* Set WordWrap variable to int with a zero default
-
+ * Fix extra lines when not using SMTP mailer
+ * Set WordWrap variable to int with a zero default
+
Version 1.47 (Tue, Oct 16 2001)
-* Fixed Received header code format
-* Fixed AltBody order error
-* Fixed alternate port warning
-
+ * Fixed Received header code format
+ * Fixed AltBody order error
+ * Fixed alternate port warning
+
Version 1.45 (Tue, Sep 25 2001)
-* Added enhanced SMTP debug support
-* Added support for multiple ports on SMTP
-* Added Received header for tracing
-* Fixed AddStringAttachment encoding
-* Fixed possible header name quote bug
-* Fixed wordwrap() trim bug
-* Couple other small bug fixes
-
+ * Added enhanced SMTP debug support
+ * Added support for multiple ports on SMTP
+ * Added Received header for tracing
+ * Fixed AddStringAttachment encoding
+ * Fixed possible header name quote bug
+ * Fixed wordwrap() trim bug
+ * Couple other small bug fixes
+
Version 1.41 (Wed, Aug 22 2001)
-* Fixed AltBody bug w/o attachments
-* Fixed rfc_date() for certain mail servers
-
+ * Fixed AltBody bug w/o attachments
+ * Fixed rfc_date() for certain mail servers
+
Version 1.40 (Sun, Aug 12 2001)
-* Added multipart/alternative support (AltBody)
-* Documentation update
-* Fixed bug in Mercury MTA
-
+ * Added multipart/alternative support (AltBody)
+ * Documentation update
+ * Fixed bug in Mercury MTA
+
Version 1.29 (Fri, Aug 03 2001)
-* Added AddStringAttachment() method
-* Added SMTP authentication support
-
+ * Added AddStringAttachment() method
+ * Added SMTP authentication support
+
Version 1.28 (Mon, Jul 30 2001)
-* Fixed a typo in SMTP class
-* Fixed header issue with Imail (win32) SMTP server
-* Made fopen() calls for attachments use "rb" to fix win32 error
-
+ * Fixed a typo in SMTP class
+ * Fixed header issue with Imail (win32) SMTP server
+ * Made fopen() calls for attachments use "rb" to fix win32 error
+
Version 1.25 (Mon, Jul 02 2001)
-* Added RFC 822 date fix (Patrice)
-* Added improved error handling by adding a $ErrorInfo variable
-* Removed MailerDebug variable (obsolete with new error handler)
-
+ * Added RFC 822 date fix (Patrice)
+ * Added improved error handling by adding a $ErrorInfo variable
+ * Removed MailerDebug variable (obsolete with new error handler)
+
Version 1.20 (Mon, Jun 25 2001)
-* Added quoted-printable encoding (Patrice)
-* Set Version as public and removed PrintVersion()
-* Changed phpdoc to only display public variables and methods
-
+ * Added quoted-printable encoding (Patrice)
+ * Set Version as public and removed PrintVersion()
+ * Changed phpdoc to only display public variables and methods
+
Version 1.19 (Thu, Jun 21 2001)
-* Fixed MS Mail header bug
-* Added fix for Bcc problem with mail(). *Does not work on Win32*
- (See PHP bug report: http://www.php.net/bugs.php?id=11616)
-* mail() no longer passes a fifth parameter when not needed
-
+ * Fixed MS Mail header bug
+ * Added fix for Bcc problem with mail(). *Does not work on Win32*
+ (See PHP bug report: http://www.php.net/bugs.php?id=11616)
+ * mail() no longer passes a fifth parameter when not needed
+
Version 1.15 (Fri, Jun 15 2001)
-[Note: these changes contributed by Patrice Fournier]
-* Changed all remaining \n to \r\n
-* Bcc: header no longer writen to message except
-when sent directly to sendmail
-* Added a small message to non-MIME compliant mail reader
-* Added Sender variable to change the Sender email
-used in -f for sendmail/mail and in 'MAIL FROM' for smtp mode
-* Changed boundary setting to a place it will be set only once
-* Removed transfer encoding for whole message when using multipart
-* Message body now uses Encoding in multipart messages
-* Can set encoding and type to attachments 7bit, 8bit
-and binary attachment are sent as is, base64 are encoded
-* Can set Encoding to base64 to send 8 bits body
-through 7 bits servers
-
+ [Note: these changes contributed by Patrice Fournier]
+ * Changed all remaining \n to \r\n
+ * Bcc: header no longer writen to message except
+ when sent directly to sendmail
+ * Added a small message to non-MIME compliant mail reader
+ * Added Sender variable to change the Sender email
+ used in -f for sendmail/mail and in 'MAIL FROM' for smtp mode
+ * Changed boundary setting to a place it will be set only once
+ * Removed transfer encoding for whole message when using multipart
+ * Message body now uses Encoding in multipart messages
+ * Can set encoding and type to attachments 7bit, 8bit
+ and binary attachment are sent as is, base64 are encoded
+ * Can set Encoding to base64 to send 8 bits body
+ through 7 bits servers
+
Version 1.10 (Tue, Jun 12 2001)
-* Fixed win32 mail header bug (printed out headers in message body)
-
+ * Fixed win32 mail header bug (printed out headers in message body)
+
Version 1.09 (Fri, Jun 08 2001)
-* Changed date header to work with Netscape mail programs
-* Altered phpdoc documentation
-
+ * Changed date header to work with Netscape mail programs
+ * Altered phpdoc documentation
+
Version 1.08 (Tue, Jun 05 2001)
-* Added enhanced error-checking
-* Added phpdoc documentation to source
-
+ * Added enhanced error-checking
+ * Added phpdoc documentation to source
+
Version 1.06 (Fri, Jun 01 2001)
-* Added optional name for file attachments
-
+ * Added optional name for file attachments
+
Version 1.05 (Tue, May 29 2001)
-* Code cleanup
-* Eliminated sendmail header warning message
-* Fixed possible SMTP error
-
+ * Code cleanup
+ * Eliminated sendmail header warning message
+ * Fixed possible SMTP error
+
Version 1.03 (Thu, May 24 2001)
-* Fixed problem where qmail sends out duplicate messages
-
+ * Fixed problem where qmail sends out duplicate messages
+
Version 1.02 (Wed, May 23 2001)
-* Added multiple recipient and attachment Clear* methods
-* Added Sendmail public variable
-* Fixed problem with loading SMTP library multiple times
-
+ * Added multiple recipient and attachment Clear* methods
+ * Added Sendmail public variable
+ * Fixed problem with loading SMTP library multiple times
+
Version 0.98 (Tue, May 22 2001)
-* Fixed problem with redundant mail hosts sending out multiple messages
-* Added additional error handler code
-* Added AddCustomHeader() function
-* Added support for Microsoft mail client headers (affects priority)
-* Fixed small bug with Mailer variable
-* Added PrintVersion() function
-
+ * Fixed problem with redundant mail hosts sending out multiple messages
+ * Added additional error handler code
+ * Added AddCustomHeader() function
+ * Added support for Microsoft mail client headers (affects priority)
+ * Fixed small bug with Mailer variable
+ * Added PrintVersion() function
+
Version 0.92 (Tue, May 15 2001)
-* Changed file names to class.phpmailer.php and class.smtp.php to match
- current PHP class trend.
-* Fixed problem where body not being printed when a message is attached
-* Several small bug fixes
-
+ * Changed file names to class.phpmailer.php and class.smtp.php to match
+ current PHP class trend.
+ * Fixed problem where body not being printed when a message is attached
+ * Several small bug fixes
+
Version 0.90 (Tue, April 17 2001)
-* Intial public release
+ * Intial public release
diff --git a/class.phpmailer.php b/class.phpmailer.php
index 22752b40d..601a8124a 100644
--- a/class.phpmailer.php
+++ b/class.phpmailer.php
@@ -2,7 +2,7 @@
/*~ class.phpmailer.php
.---------------------------------------------------------------------------.
| Software: PHPMailer - PHP email class |
-| Version: 5.2.1 |
+| Version: 5.2.2 |
| Site: https://code.google.com/a/apache-extras.org/p/phpmailer/ |
| ------------------------------------------------------------------------- |
| Admin: Jim Jagielski (project admininistrator) |
@@ -23,7 +23,7 @@
*/
/**
- * PHPMailer - PHP email transport class
+ * PHPMailer - PHP email creation and transport class
* NOTE: Requires PHP version 5 or later
* @package PHPMailer
* @author Andy Prevost
@@ -31,12 +31,15 @@
* @author Jim Jagielski
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
- * @version $Id: class.phpmailer.php 450 2010-06-23 16:46:33Z coolbru $
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n");
+/**
+ * PHP email creation and transport class
+ * @package PHPMailer
+ */
class PHPMailer {
/////////////////////////////////////////////////
@@ -94,6 +97,13 @@ class PHPMailer {
public $Sender = '';
/**
+ * Sets the Return-Path of the message. If empty, it will
+ * be set to either From or Sender.
+ * @var string
+ */
+ public $ReturnPath = '';
+
+ /**
* Sets the Subject of the message.
* @var string
*/
@@ -130,11 +140,11 @@ class PHPMailer {
protected $MIMEHeader = '';
/**
- * Stores the complete sent MIME message (Body and Headers)
+ * Stores the extra header list which CreateHeader() doesn't fold in
* @var string
* @access protected
- */
- protected $SentMIMEMessage = '';
+ */
+ protected $mailHeader = '';
/**
* Sets word wrapping on the body of the message to a given number of
@@ -155,6 +165,13 @@ class PHPMailer {
*/
public $Sendmail = '/usr/sbin/sendmail';
+ /**
+ * Determine if mail() uses a fully sendmail compatible MTA that
+ * supports sendmail's "-oi -f" options
+ * @var boolean
+ */
+ public $UseSendmailOptions = true;
+
/**
* Path to PHPMailer plugins. Useful if the SMTP class
* is in a different directory than the PHP include path.
@@ -183,12 +200,21 @@ class PHPMailer {
*/
public $MessageID = '';
+ /**
+ * Sets the message Date to be used in the Date header.
+ * If empty, the current date will be added.
+ * @var string
+ */
+ public $MessageDate = '';
+
/////////////////////////////////////////////////
// PROPERTIES FOR SMTP
/////////////////////////////////////////////////
/**
- * Sets the SMTP hosts. All hosts must be separated by a
+ * Sets the SMTP hosts.
+ *
+ * All hosts must be separated by a
* semicolon. You can also specify a different port
* for each host by using this format: [hostname:port]
* (e.g. "smtp1.example.com:25;smtp2.example.com").
@@ -210,8 +236,7 @@ class PHPMailer {
public $Helo = '';
/**
- * Sets connection prefix.
- * Options are "", "ssl" or "tls"
+ * Sets connection prefix. Options are "", "ssl" or "tls"
* @var string
*/
public $SMTPSecure = '';
@@ -234,6 +259,24 @@ class PHPMailer {
*/
public $Password = '';
+ /**
+ * Sets SMTP auth type. Options are LOGIN | PLAIN | NTLM (default LOGIN)
+ * @var string
+ */
+ public $AuthType = '';
+
+ /**
+ * Sets SMTP realm.
+ * @var string
+ */
+ public $Realm = '';
+
+ /**
+ * Sets SMTP workstation.
+ * @var string
+ */
+ public $Workstation = '';
+
/**
* Sets the SMTP server timeout in seconds.
* This function will not work with the win32 version.
@@ -247,6 +290,13 @@ class PHPMailer {
*/
public $SMTPDebug = false;
+ /**
+ * Sets the function/method to use for debugging output.
+ * Right now we only honor "echo" or "error_log"
+ * @var string
+ */
+ public $Debugoutput = "echo";
+
/**
* Prevents the SMTP connection from being closed after each mail
* sending. If this is set to true then to close the connection
@@ -269,53 +319,69 @@ class PHPMailer {
public $SingleToArray = array();
/**
- * Provides the ability to change the line ending
+ * Provides the ability to change the generic line ending
+ * NOTE: The default remains '\n'. We force CRLF where we KNOW
+ * it must be used via self::CRLF
* @var string
*/
public $LE = "\n";
- /**
- * Used with DKIM DNS Resource Record
+ /**
+ * Used with DKIM Signing
+ * required parameter if DKIM is enabled
+ *
+ * domain selector example domainkey
* @var string
*/
- public $DKIM_selector = 'phpmailer';
+ public $DKIM_selector = '';
/**
- * Used with DKIM DNS Resource Record
- * optional, in format of email address 'you@yourdomain.com'
+ * Used with DKIM Signing
+ * required if DKIM is enabled, in format of email address 'you@yourdomain.com' typically used as the source of the email
* @var string
*/
public $DKIM_identity = '';
/**
- * Used with DKIM DNS Resource Record
+ * Used with DKIM Signing
+ * optional parameter if your private key requires a passphras
* @var string
*/
public $DKIM_passphrase = '';
/**
- * Used with DKIM DNS Resource Record
- * optional, in format of email address 'you@yourdomain.com'
+ * Used with DKIM Singing
+ * required if DKIM is enabled, in format of email address 'domain.com'
* @var string
*/
public $DKIM_domain = '';
/**
- * Used with DKIM DNS Resource Record
- * optional, in format of email address 'you@yourdomain.com'
+ * Used with DKIM Signing
+ * required if DKIM is enabled, path to private key file
* @var string
*/
public $DKIM_private = '';
/**
- * Callback Action function name
- * the function that handles the result of the send email action. Parameters:
+ * Callback Action function name.
+ * The function that handles the result of the send email action.
+ * It is called out by Send() for each email sent.
+ *
+ * Value can be:
+ * - 'function_name' for function names
+ * - 'Class::Method' for static method calls
+ * - array($object, 'Method') for calling methods on $object
+ * See http://php.net/is_callable manual page for more details.
+ *
+ * Parameters:
* bool $result result of the send action
* string $to email address of the recipient
* string $cc cc email addresses
* string $bcc bcc email addresses
* string $subject the subject
* string $body the email body
+ * string $from email address of sender
* @var string
*/
public $action_function = ''; //'callbackAction';
@@ -324,11 +390,11 @@ class PHPMailer {
* Sets the PHPMailer Version number
* @var string
*/
- public $Version = '5.2.1';
+ public $Version = '5.2.2-rc2';
/**
* What to use in the X-Mailer header
- * @var string
+ * @var string NULL for default, whitespace for None, or actual string to use
*/
public $XMailer = '';
@@ -336,21 +402,85 @@ class PHPMailer {
// PROPERTIES, PRIVATE AND PROTECTED
/////////////////////////////////////////////////
- protected $smtp = NULL;
+ /**
+ * @var SMTP An instance of the SMTP sender class
+ * @access protected
+ */
+ protected $smtp = null;
+ /**
+ * @var array An array of 'to' addresses
+ * @access protected
+ */
protected $to = array();
+ /**
+ * @var array An array of 'cc' addresses
+ * @access protected
+ */
protected $cc = array();
+ /**
+ * @var array An array of 'bcc' addresses
+ * @access protected
+ */
protected $bcc = array();
+ /**
+ * @var array An array of reply-to name and address
+ * @access protected
+ */
protected $ReplyTo = array();
+ /**
+ * @var array An array of all kinds of addresses: to, cc, bcc, replyto
+ * @access protected
+ */
protected $all_recipients = array();
+ /**
+ * @var array An array of attachments
+ * @access protected
+ */
protected $attachment = array();
+ /**
+ * @var array An array of custom headers
+ * @access protected
+ */
protected $CustomHeader = array();
+ /**
+ * @var string The message's MIME type
+ * @access protected
+ */
protected $message_type = '';
+ /**
+ * @var array An array of MIME boundary strings
+ * @access protected
+ */
protected $boundary = array();
+ /**
+ * @var array An array of available languages
+ * @access protected
+ */
protected $language = array();
+ /**
+ * @var integer The number of errors encountered
+ * @access protected
+ */
protected $error_count = 0;
+ /**
+ * @var string The filename of a DKIM certificate file
+ * @access protected
+ */
protected $sign_cert_file = '';
+ /**
+ * @var string The filename of a DKIM key file
+ * @access protected
+ */
protected $sign_key_file = '';
+ /**
+ * @var string The password of a DKIM key
+ * @access protected
+ */
protected $sign_key_pass = '';
+ /**
+ * @var boolean Whether to throw exceptions for errors
+ * @access protected
+ */
protected $exceptions = false;
/////////////////////////////////////////////////
@@ -360,11 +490,46 @@ class PHPMailer {
const STOP_MESSAGE = 0; // message only, continue processing
const STOP_CONTINUE = 1; // message?, likely ok to continue processing
const STOP_CRITICAL = 2; // message, plus full stop, critical error reached
+ const CRLF = "\r\n"; // SMTP RFC specified EOL
/////////////////////////////////////////////////
// METHODS, VARIABLES
/////////////////////////////////////////////////
+ /**
+ * Calls actual mail() function, but in a safe_mode aware fashion
+ * Also, unless sendmail_path points to sendmail (or something that
+ * claims to be sendmail), don't pass params (not a perfect fix,
+ * but it will do)
+ * @param string $to To
+ * @param string $subject Subject
+ * @param string $body Message Body
+ * @param string $header Additional Header(s)
+ * @param string $params Params
+ * @access private
+ * @return bool
+ */
+ private function mail_passthru($to, $subject, $body, $header, $params) {
+ if ( ini_get('safe_mode') || !($this->UseSendmailOptions) ) {
+ $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header);
+ } else {
+ $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header, $params);
+ }
+ return $rt;
+ }
+
+ /**
+ * Outputs debugging info via user-defined method
+ * @param string $str
+ */
+ private function edebug($str) {
+ if ($this->Debugoutput == "error_log") {
+ error_log($str);
+ } else {
+ echo $str;
+ }
+ }
+
/**
* Constructor
* @param boolean $exceptions Should we throw external exceptions?
@@ -389,6 +554,7 @@ public function IsHTML($ishtml = true) {
/**
* Sets Mailer to send message using SMTP.
* @return void
+ * @deprecated
*/
public function IsSMTP() {
$this->Mailer = 'smtp';
@@ -397,6 +563,7 @@ public function IsSMTP() {
/**
* Sets Mailer to send message using PHP mail() function.
* @return void
+ * @deprecated
*/
public function IsMail() {
$this->Mailer = 'mail';
@@ -405,6 +572,7 @@ public function IsMail() {
/**
* Sets Mailer to send message using the $Sendmail program.
* @return void
+ * @deprecated
*/
public function IsSendmail() {
if (!stristr(ini_get('sendmail_path'), 'sendmail')) {
@@ -416,6 +584,7 @@ public function IsSendmail() {
/**
* Sets Mailer to send message using the qmail MTA.
* @return void
+ * @deprecated
*/
public function IsQmail() {
if (stristr(ini_get('sendmail_path'), 'qmail')) {
@@ -476,6 +645,7 @@ public function AddReplyTo($address, $name = '') {
* @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
* @param string $address The email address to send to
* @param string $name
+ * @throws phpmailerException
* @return boolean true on success, false if address already used or invalid in some way
* @access protected
*/
@@ -485,20 +655,20 @@ protected function AddAnAddress($kind, $address, $name = '') {
if ($this->exceptions) {
throw new phpmailerException('Invalid recipient array: ' . $kind);
}
- if ($this->SMTPDebug) {
- echo $this->Lang('Invalid recipient array').': '.$kind;
+ if ($this->SMTPDebug) {
+ $this->edebug($this->Lang('Invalid recipient array').': '.$kind);
}
return false;
}
$address = trim($address);
$name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
- if (!self::ValidateAddress($address)) {
+ if (!$this->ValidateAddress($address)) {
$this->SetError($this->Lang('invalid_address').': '. $address);
if ($this->exceptions) {
throw new phpmailerException($this->Lang('invalid_address').': '.$address);
}
- if ($this->SMTPDebug) {
- echo $this->Lang('invalid_address').': '.$address;
+ if ($this->SMTPDebug) {
+ $this->edebug($this->Lang('invalid_address').': '.$address);
}
return false;
}
@@ -517,22 +687,24 @@ protected function AddAnAddress($kind, $address, $name = '') {
return false;
}
-/**
- * Set the From and FromName properties
- * @param string $address
- * @param string $name
- * @return boolean
- */
+ /**
+ * Set the From and FromName properties
+ * @param string $address
+ * @param string $name
+ * @param int $auto Also set Reply-To and Sender
+ * @throws phpmailerException
+ * @return boolean
+ */
public function SetFrom($address, $name = '', $auto = 1) {
$address = trim($address);
$name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
- if (!self::ValidateAddress($address)) {
+ if (!$this->ValidateAddress($address)) {
$this->SetError($this->Lang('invalid_address').': '. $address);
if ($this->exceptions) {
throw new phpmailerException($this->Lang('invalid_address').': '.$address);
}
- if ($this->SMTPDebug) {
- echo $this->Lang('invalid_address').': '.$address;
+ if ($this->SMTPDebug) {
+ $this->edebug($this->Lang('invalid_address').': '.$address);
}
return false;
}
@@ -551,25 +723,19 @@ public function SetFrom($address, $name = '', $auto = 1) {
/**
* Check that a string looks roughly like an email address should
- * Static so it can be used without instantiation
- * Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator
- * Conforms approximately to RFC2822
- * @link http://www.hexillion.com/samples/#Regex Original pattern found here
+ * Static so it can be used without instantiation, public so people can overload
+ * Conforms to RFC5322: Uses *correct* regex on which FILTER_VALIDATE_EMAIL is
+ * based; So why not use FILTER_VALIDATE_EMAIL? Because it was broken to
+ * not allow a@b type valid addresses :(
+ * @link http://squiloople.com/2009/12/20/email-address-validation/
+ * @copyright regex Copyright Michael Rushton 2009-10 | http://squiloople.com/ | Feel free to use and redistribute this code. But please keep this copyright notice.
* @param string $address The email address to check
* @return boolean
* @static
* @access public
*/
public static function ValidateAddress($address) {
- if (function_exists('filter_var')) { //Introduced in PHP 5.2
- if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
- return false;
- } else {
- return true;
- }
- } else {
- return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address);
- }
+ return preg_match('/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\x0D\x0A)?[ ])+|(?>[ ]*\x0D\x0A)?[ ]+)?)(\((?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}|(?!(?:.*[a-f0-9][:\]]){7,})((?6)(?>:(?6)){0,5})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){5,})(?8)?::(?>((?6)(?>:(?6)){0,3}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address);
}
/////////////////////////////////////////////////
@@ -580,6 +746,7 @@ public static function ValidateAddress($address) {
* Creates message and assigns Mailer. If the message is
* not sent successfully then it returns false. Use the ErrorInfo
* variable to view description of the error.
+ * @throws phpmailerException
* @return bool
*/
public function Send() {
@@ -587,7 +754,7 @@ public function Send() {
if(!$this->PreSend()) return false;
return $this->PostSend();
} catch (phpmailerException $e) {
- $this->SentMIMEMessage = '';
+ $this->mailHeader = '';
$this->SetError($e->getMessage());
if ($this->exceptions) {
throw $e;
@@ -596,9 +763,14 @@ public function Send() {
}
}
- protected function PreSend() {
+ /**
+ * Prep mail by constructing all message entities
+ * @throws phpmailerException
+ * @return bool
+ */
+ public function PreSend() {
try {
- $mailHeader = "";
+ $this->mailHeader = "";
if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
}
@@ -619,26 +791,25 @@ protected function PreSend() {
$this->MIMEBody = $this->CreateBody();
// To capture the complete message when using mail(), create
- // an extra header list which CreateHeader() doesn't fold in
+ // an extra header list which CreateHeader() doesn't fold in
if ($this->Mailer == 'mail') {
if (count($this->to) > 0) {
- $mailHeader .= $this->AddrAppend("To", $this->to);
+ $this->mailHeader .= $this->AddrAppend("To", $this->to);
} else {
- $mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");
+ $this->mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");
}
- $mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));
+ $this->mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));
// if(count($this->cc) > 0) {
- // $mailHeader .= $this->AddrAppend("Cc", $this->cc);
+ // $this->mailHeader .= $this->AddrAppend("Cc", $this->cc);
// }
}
// digitally sign with DKIM if enabled
- if ($this->DKIM_domain && $this->DKIM_private) {
+ if (!empty($this->DKIM_domain) && !empty($this->DKIM_private) && !empty($this->DKIM_selector) && !empty($this->DKIM_domain) && file_exists($this->DKIM_private)) {
$header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody);
$this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader;
}
- $this->SentMIMEMessage = sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$mailHeader,$this->MIMEBody);
return true;
} catch (phpmailerException $e) {
@@ -650,7 +821,13 @@ protected function PreSend() {
}
}
- protected function PostSend() {
+ /**
+ * Actual Email transport function
+ * Send the email via the selected mechanism
+ * @throws phpmailerException
+ * @return bool
+ */
+ public function PostSend() {
try {
// Choose the mailer and send through it
switch($this->Mailer) {
@@ -663,34 +840,34 @@ protected function PostSend() {
default:
return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
}
-
} catch (phpmailerException $e) {
$this->SetError($e->getMessage());
if ($this->exceptions) {
throw $e;
}
- if ($this->SMTPDebug) {
- echo $e->getMessage()."\n";
+ if ($this->SMTPDebug) {
+ $this->edebug($e->getMessage()."\n");
}
- return false;
}
+ return false;
}
/**
* Sends mail using the $Sendmail program.
* @param string $header The message headers
* @param string $body The message body
+ * @throws phpmailerException
* @access protected
* @return bool
*/
protected function SendmailSend($header, $body) {
if ($this->Sender != '') {
- $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
+ $sendmail = sprintf("%s -oi -f%s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
} else {
$sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
}
if ($this->SingleTo === true) {
- foreach ($this->SingleToArray as $key => $val) {
+ foreach ($this->SingleToArray as $val) {
if(!@$mail = popen($sendmail, 'w')) {
throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
}
@@ -722,13 +899,14 @@ protected function SendmailSend($header, $body) {
return true;
}
- /**
- * Sends mail using the PHP mail() function.
- * @param string $header The message headers
- * @param string $body The message body
- * @access protected
- * @return bool
- */
+ /**
+ * Sends mail using the PHP mail() function.
+ * @param string $header The message headers
+ * @param string $body The message body
+ * @throws phpmailerException
+ * @access protected
+ * @return bool
+ */
protected function MailSend($header, $body) {
$toArr = array();
foreach($this->to as $t) {
@@ -739,38 +917,25 @@ protected function MailSend($header, $body) {
if (empty($this->Sender)) {
$params = "-oi ";
} else {
- $params = sprintf("-oi -f %s", $this->Sender);
+ $params = sprintf("-oi -f%s", $this->Sender);
}
if ($this->Sender != '' and !ini_get('safe_mode')) {
$old_from = ini_get('sendmail_from');
ini_set('sendmail_from', $this->Sender);
- if ($this->SingleTo === true && count($toArr) > 1) {
- foreach ($toArr as $key => $val) {
- $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
- // implement call back function if it exists
- $isSent = ($rt == 1) ? 1 : 0;
- $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
- }
- } else {
- $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
+ }
+ $rt = false;
+ if ($this->SingleTo === true && count($toArr) > 1) {
+ foreach ($toArr as $val) {
+ $rt = $this->mail_passthru($val, $this->Subject, $body, $header, $params);
// implement call back function if it exists
$isSent = ($rt == 1) ? 1 : 0;
- $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
+ $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
}
} else {
- if ($this->SingleTo === true && count($toArr) > 1) {
- foreach ($toArr as $key => $val) {
- $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
- // implement call back function if it exists
- $isSent = ($rt == 1) ? 1 : 0;
- $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
- }
- } else {
- $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
- // implement call back function if it exists
- $isSent = ($rt == 1) ? 1 : 0;
- $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
- }
+ $rt = $this->mail_passthru($to, $this->Subject, $body, $header, $params);
+ // implement call back function if it exists
+ $isSent = ($rt == 1) ? 1 : 0;
+ $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
}
if (isset($old_from)) {
ini_set('sendmail_from', $old_from);
@@ -786,6 +951,7 @@ protected function MailSend($header, $body) {
* Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
* @param string $header The message headers
* @param string $body The message body
+ * @throws phpmailerException
* @uses SMTP
* @access protected
* @return bool
@@ -850,6 +1016,9 @@ protected function SmtpSend($header, $body) {
}
if($this->SMTPKeepAlive == true) {
$this->smtp->Reset();
+ } else {
+ $this->smtp->Quit();
+ $this->smtp->Close();
}
return true;
}
@@ -859,13 +1028,15 @@ protected function SmtpSend($header, $body) {
* Returns false if the operation failed.
* @uses SMTP
* @access public
+ * @throws phpmailerException
* @return bool
*/
public function SmtpConnect() {
if(is_null($this->smtp)) {
- $this->smtp = new SMTP();
+ $this->smtp = new SMTP;
}
+ $this->smtp->Timeout = $this->Timeout;
$this->smtp->do_debug = $this->SMTPDebug;
$hosts = explode(';', $this->Host);
$index = 0;
@@ -902,7 +1073,8 @@ public function SmtpConnect() {
$connection = true;
if ($this->SMTPAuth) {
- if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
+ if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType,
+ $this->Realm, $this->Workstation)) {
throw new phpmailerException($this->Lang('authenticate'));
}
}
@@ -926,7 +1098,7 @@ public function SmtpConnect() {
* @return void
*/
public function SmtpClose() {
- if(!is_null($this->smtp)) {
+ if ($this->smtp !== null) {
if($this->smtp->Connected()) {
$this->smtp->Quit();
$this->smtp->Close();
@@ -935,32 +1107,34 @@ public function SmtpClose() {
}
/**
- * Sets the language for all class error messages.
- * Returns false if it cannot load the language file. The default language is English.
- * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br")
- * @param string $lang_path Path to the language file directory
- * @access public
- */
+ * Sets the language for all class error messages.
+ * Returns false if it cannot load the language file. The default language is English.
+ * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br")
+ * @param string $lang_path Path to the language file directory
+ * @return bool
+ * @access public
+ */
function SetLanguage($langcode = 'en', $lang_path = 'language/') {
//Define full set of translatable strings
$PHPMAILER_LANG = array(
- 'provide_address' => 'You must provide at least one recipient email address.',
+ 'authenticate' => 'SMTP Error: Could not authenticate.',
+ 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
+ 'data_not_accepted' => 'SMTP Error: Data not accepted.',
+ 'empty_message' => 'Message body empty',
+ 'encoding' => 'Unknown encoding: ',
+ 'execute' => 'Could not execute: ',
+ 'file_access' => 'Could not access file: ',
+ 'file_open' => 'File Error: Could not open file: ',
+ 'from_failed' => 'The following From address failed: ',
+ 'instantiate' => 'Could not instantiate mail function.',
+ 'invalid_address' => 'Invalid address',
'mailer_not_supported' => ' mailer is not supported.',
- 'execute' => 'Could not execute: ',
- 'instantiate' => 'Could not instantiate mail function.',
- 'authenticate' => 'SMTP Error: Could not authenticate.',
- 'from_failed' => 'The following From address failed: ',
- 'recipients_failed' => 'SMTP Error: The following recipients failed: ',
- 'data_not_accepted' => 'SMTP Error: Data not accepted.',
- 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
- 'file_access' => 'Could not access file: ',
- 'file_open' => 'File Error: Could not open file: ',
- 'encoding' => 'Unknown encoding: ',
- 'signing' => 'Signing Error: ',
- 'smtp_error' => 'SMTP server error: ',
- 'empty_message' => 'Message body empty',
- 'invalid_address' => 'Invalid address',
- 'variable_set' => 'Cannot set or reset variable: '
+ 'provide_address' => 'You must provide at least one recipient email address.',
+ 'recipients_failed' => 'SMTP Error: The following recipients failed: ',
+ 'signing' => 'Signing Error: ',
+ 'smtp_connect_failed' => 'SMTP Connect() failed.',
+ 'smtp_error' => 'SMTP server error: ',
+ 'variable_set' => 'Cannot set or reset variable: '
);
//Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"!
$l = true;
@@ -986,6 +1160,8 @@ public function GetTranslations() {
/**
* Creates recipient headers.
* @access public
+ * @param string $type
+ * @param array $addr
* @return string
*/
public function AddrAppend($type, $addr) {
@@ -1003,6 +1179,7 @@ public function AddrAppend($type, $addr) {
/**
* Formats an address correctly.
* @access public
+ * @param string $addr
* @return string
*/
public function AddrFormat($addr) {
@@ -1028,13 +1205,15 @@ public function WrapText($message, $length, $qp_mode = false) {
// If utf-8 encoding is used, we will need to make sure we don't
// split multibyte characters when we wrap
$is_utf8 = (strtolower($this->CharSet) == "utf-8");
+ $lelen = strlen($this->LE);
+ $crlflen = strlen(self::CRLF);
$message = $this->FixEOL($message);
- if (substr($message, -1) == $this->LE) {
- $message = substr($message, 0, -1);
+ if (substr($message, -$lelen) == $this->LE) {
+ $message = substr($message, 0, -$lelen);
}
- $line = explode($this->LE, $message);
+ $line = explode($this->LE, $message); // Magic. We know FixEOL uses $LE
$message = '';
for ($i = 0 ;$i < count($line); $i++) {
$line_part = explode(' ', $line[$i]);
@@ -1042,7 +1221,7 @@ public function WrapText($message, $length, $qp_mode = false) {
for ($e = 0; $e $length)) {
- $space_left = $length - strlen($buf) - 1;
+ $space_left = $length - strlen($buf) - $crlflen;
if ($e != 0) {
if ($space_left > 20) {
$len = $space_left;
@@ -1056,7 +1235,7 @@ public function WrapText($message, $length, $qp_mode = false) {
$part = substr($word, 0, $len);
$word = substr($word, $len);
$buf .= ' ' . $part;
- $message .= $buf . sprintf("=%s", $this->LE);
+ $message .= $buf . sprintf("=%s", self::CRLF);
} else {
$message .= $buf . $soft_break;
}
@@ -1075,7 +1254,7 @@ public function WrapText($message, $length, $qp_mode = false) {
$word = substr($word, $len);
if (strlen($word) > 0) {
- $message .= $part . sprintf("=%s", $this->LE);
+ $message .= $part . sprintf("=%s", self::CRLF);
} else {
$buf = $part;
}
@@ -1090,7 +1269,7 @@ public function WrapText($message, $length, $qp_mode = false) {
}
}
}
- $message .= $buf . $this->LE;
+ $message .= $buf . self::CRLF;
}
return $message;
@@ -1175,8 +1354,15 @@ public function CreateHeader() {
$this->boundary[2] = 'b2_' . $uniq_id;
$this->boundary[3] = 'b3_' . $uniq_id;
- $result .= $this->HeaderLine('Date', self::RFCDate());
- if($this->Sender == '') {
+ if ($this->MessageDate == '') {
+ $result .= $this->HeaderLine('Date', self::RFCDate());
+ } else {
+ $result .= $this->HeaderLine('Date', $this->MessageDate);
+ }
+
+ if ($this->ReturnPath) {
+ $result .= $this->HeaderLine('Return-Path', trim($this->ReturnPath));
+ } elseif ($this->Sender == '') {
$result .= $this->HeaderLine('Return-Path', trim($this->From));
} else {
$result .= $this->HeaderLine('Return-Path', trim($this->Sender));
@@ -1195,7 +1381,7 @@ public function CreateHeader() {
$result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
}
}
- }
+ }
$from = array();
$from[0][0] = trim($this->From);
@@ -1227,10 +1413,13 @@ public function CreateHeader() {
$result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
}
$result .= $this->HeaderLine('X-Priority', $this->Priority);
- if($this->XMailer) {
- $result .= $this->HeaderLine('X-Mailer', $this->XMailer);
+ if ($this->XMailer == '') {
+ $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
} else {
- $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
+ $myXmailer = trim($this->XMailer);
+ if ($myXmailer) {
+ $result .= $this->HeaderLine('X-Mailer', $myXmailer);
+ }
}
if($this->ConfirmReadingTo != '') {
@@ -1257,10 +1446,6 @@ public function CreateHeader() {
public function GetMailMIME() {
$result = '';
switch($this->message_type) {
- case 'plain':
- $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
- $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset='.$this->CharSet);
- break;
case 'inline':
$result .= $this->HeaderLine('Content-Type', 'multipart/related;');
$result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
@@ -1277,10 +1462,15 @@ public function GetMailMIME() {
$result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
$result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
break;
+ default:
+ // Catches case 'plain': and case '':
+ $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
+ $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset='.$this->CharSet);
+ break;
}
if($this->Mailer != 'mail') {
- $result .= $this->LE.$this->LE;
+ $result .= $this->LE;
}
return $result;
@@ -1292,28 +1482,26 @@ public function GetMailMIME() {
* @return string
*/
public function GetSentMIMEMessage() {
- return $this->SentMIMEMessage;
+ return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody;
}
/**
* Assembles the message body. Returns an empty string on failure.
* @access public
+ * @throws phpmailerException
* @return string The assembled message body
*/
public function CreateBody() {
$body = '';
if ($this->sign_key_file) {
- $body .= $this->GetMailMIME();
+ $body .= $this->GetMailMIME().$this->LE;
}
$this->SetWordWrap();
switch($this->message_type) {
- case 'plain':
- $body .= $this->EncodeString($this->Body, $this->Encoding);
- break;
case 'inline':
$body .= $this->GetBoundary($this->boundary[1], '', '', '');
$body .= $this->EncodeString($this->Body, $this->Encoding);
@@ -1398,6 +1586,10 @@ public function CreateBody() {
$body .= $this->LE;
$body .= $this->AttachAll("attachment", $this->boundary[1]);
break;
+ default:
+ // catch case 'plain' and case ''
+ $body .= $this->EncodeString($this->Body, $this->Encoding);
+ break;
}
if ($this->IsError()) {
@@ -1430,6 +1622,10 @@ public function CreateBody() {
/**
* Returns the start of a message boundary.
* @access protected
+ * @param string $boundary
+ * @param string $charSet
+ * @param string $contentType
+ * @param string $encoding
* @return string
*/
protected function GetBoundary($boundary, $charSet, $contentType, $encoding) {
@@ -1455,6 +1651,7 @@ protected function GetBoundary($boundary, $charSet, $contentType, $encoding) {
/**
* Returns the end of a message boundary.
* @access protected
+ * @param string $boundary
* @return string
*/
protected function EndBoundary($boundary) {
@@ -1476,8 +1673,10 @@ protected function SetMessageType() {
}
/**
- * Returns a formatted header line.
+ * Returns a formatted header line.
* @access public
+ * @param string $name
+ * @param string $value
* @return string
*/
public function HeaderLine($name, $value) {
@@ -1487,6 +1686,7 @@ public function HeaderLine($name, $value) {
/**
* Returns a formatted mail line.
* @access public
+ * @param string $value
* @return string
*/
public function TextLine($value) {
@@ -1505,6 +1705,7 @@ public function TextLine($value) {
* @param string $name Overrides the attachment name.
* @param string $encoding File encoding (see $Encoding).
* @param string $type File extension (MIME) type.
+ * @throws phpmailerException
* @return bool
*/
public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
@@ -1533,8 +1734,8 @@ public function AddAttachment($path, $name = '', $encoding = 'base64', $type = '
if ($this->exceptions) {
throw $e;
}
- if ($this->SMTPDebug) {
- echo $e->getMessage()."\n";
+ if ($this->SMTPDebug) {
+ $this->edebug($e->getMessage()."\n");
}
if ( $e->getCode() == self::STOP_CRITICAL ) {
return false;
@@ -1555,6 +1756,8 @@ public function GetAttachments() {
* Attaches all fs, string, and binary attachments to the message.
* Returns an empty string on failure.
* @access protected
+ * @param string $disposition_type
+ * @param string $boundary
* @return string
*/
protected function AttachAll($disposition_type, $boundary) {
@@ -1568,6 +1771,8 @@ protected function AttachAll($disposition_type, $boundary) {
// CHECK IF IT IS A VALID DISPOSITION_FILTER
if($attachment[6] == $disposition_type) {
// Check for string attachment
+ $string = '';
+ $path = '';
$bString = $attachment[5];
if ($bString) {
$string = $attachment[0];
@@ -1624,6 +1829,7 @@ protected function AttachAll($disposition_type, $boundary) {
* Returns an empty string on failure.
* @param string $path The full path to the file
* @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
+ * @throws phpmailerException
* @see EncodeFile()
* @access protected
* @return string
@@ -1633,28 +1839,23 @@ protected function EncodeFile($path, $encoding = 'base64') {
if (!is_readable($path)) {
throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
}
- if (function_exists('get_magic_quotes')) {
- function get_magic_quotes() {
- return false;
- }
- }
- $magic_quotes = get_magic_quotes_runtime();
- if ($magic_quotes) {
+ $magic_quotes = get_magic_quotes_runtime();
+ if ($magic_quotes) {
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
set_magic_quotes_runtime(0);
} else {
- ini_set('magic_quotes_runtime', 0);
- }
- }
+ ini_set('magic_quotes_runtime', 0);
+ }
+ }
$file_buffer = file_get_contents($path);
$file_buffer = $this->EncodeString($file_buffer, $encoding);
- if ($magic_quotes) {
+ if ($magic_quotes) {
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
set_magic_quotes_runtime($magic_quotes);
} else {
- ini_set('magic_quotes_runtime', $magic_quotes);
- }
- }
+ ini_set('magic_quotes_runtime', $magic_quotes);
+ }
+ }
return $file_buffer;
} catch (Exception $e) {
$this->SetError($e->getMessage());
@@ -1699,6 +1900,8 @@ public function EncodeString($str, $encoding = 'base64') {
/**
* Encode a header string to best (shortest) of Q, B, quoted or none.
* @access public
+ * @param string $str
+ * @param string $position
* @return string
*/
public function EncodeHeader($str, $position = 'text') {
@@ -1737,7 +1940,7 @@ public function EncodeHeader($str, $position = 'text') {
if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
// Use a custom function which correctly encodes and wraps long
// multibyte strings without breaking lines within a character
- $encoded = $this->Base64EncodeWrapMB($str);
+ $encoded = $this->Base64EncodeWrapMB($str, "\n");
} else {
$encoded = base64_encode($str);
$maxlen -= $maxlen % 4;
@@ -1747,7 +1950,7 @@ public function EncodeHeader($str, $position = 'text') {
$encoding = 'Q';
$encoded = $this->EncodeQ($str, $position);
$encoded = $this->WrapText($encoded, $maxlen, true);
- $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
+ $encoded = str_replace('='.self::CRLF, "\n", trim($encoded));
}
$encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
@@ -1776,12 +1979,16 @@ public function HasMultiBytes($str) {
* Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
* @access public
* @param string $str multi-byte text to wrap encode
+ * @param string $lf string to use as linefeed/end-of-line
* @return string
*/
- public function Base64EncodeWrapMB($str) {
+ public function Base64EncodeWrapMB($str, $lf=null) {
$start = "=?".$this->CharSet."?B?";
$end = "?=";
$encoded = "";
+ if ($lf === null) {
+ $lf = $this->LE;
+ }
$mb_length = mb_strlen($str, $this->CharSet);
// Each line must have length <= 75, including $start and $end
@@ -1802,22 +2009,24 @@ public function Base64EncodeWrapMB($str) {
}
while (strlen($chunk) > $length);
- $encoded .= $chunk . $this->LE;
+ $encoded .= $chunk . $lf;
}
// Chomp the last linefeed
- $encoded = substr($encoded, 0, -strlen($this->LE));
+ $encoded = substr($encoded, 0, -strlen($lf));
return $encoded;
}
/**
- * Encode string to quoted-printable.
- * Only uses standard PHP, slow, but will always work
- * @access public
- * @param string $string the text to encode
- * @param integer $line_max Number of chars allowed on a line before wrapping
- * @return string
- */
+ * Encode string to quoted-printable.
+ * Only uses standard PHP, slow, but will always work
+ * @access public
+ * @param string $input
+ * @param integer $line_max Number of chars allowed on a line before wrapping
+ * @param bool $space_conv
+ * @internal param string $string the text to encode
+ * @return string
+ */
public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) {
$hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
$lines = preg_split('/(?:\r\n|\r|\n)/', $input);
@@ -1840,8 +2049,8 @@ public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) {
$c = '=20';
}
} elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
- $h2 = floor($dec/16);
- $h1 = floor($dec%16);
+ $h2 = (integer)floor($dec/16);
+ $h1 = (integer)floor($dec%16);
$c = $escape.$hex[$h2].$hex[$h1];
}
if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
@@ -1901,29 +2110,37 @@ public function EncodeQP($string, $line_max = 76, $space_conv = false) {
* @return string
*/
public function EncodeQ($str, $position = 'text') {
- // There should not be any EOL in the string
- $encoded = preg_replace('/[\r\n]*/', '', $str);
-
+ //There should not be any EOL in the string
+ $pattern="";
+ $encoded = str_replace(array("\r", "\n"), '', $str);
switch (strtolower($position)) {
case 'phrase':
- $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
+ $pattern = '^A-Za-z0-9!*+\/ -';
break;
+
case 'comment':
- $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
+ $pattern = '\(\)"';
+ //note that we dont break here!
+ //for this reason we build the $pattern withoud including delimiters and []
+
case 'text':
default:
- // Replace every high ascii, control =, ? and _ characters
- //TODO using /e (equivalent to eval()) is probably not a good idea
- $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
- "'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded);
+ //Replace every high ascii, control =, ? and _ characters
+ //We put \075 (=) as first value to make sure it's the first one in being converted, preventing double encode
+ $pattern = '\075\000-\011\013\014\016-\037\077\137\177-\377' . $pattern;
break;
}
- // Replace every spaces to _ (more readable than =20)
- $encoded = str_replace(' ', '_', $encoded);
+ if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
+ foreach (array_unique($matches[0]) as $char) {
+ $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
+ }
+ }
+
+ //Replace every spaces to _ (more readable than =20)
+ return str_replace(' ', '_', $encoded);
+}
- return $encoded;
- }
/**
* Adds a string or binary attachment (non-filesystem) to the list.
@@ -1989,6 +2206,14 @@ public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64',
return true;
}
+ /**
+ * Add an embedded image from a binary string, e.g. one loaded with file_get_contents or generated with gd
+ * @param string $string Binary image data
+ * @param string $cid Content identifier
+ * @param string $filename
+ * @param string $encoding
+ * @param string $type
+ */
public function AddStringEmbeddedImage($string, $cid, $filename = '', $encoding = 'base64', $type = 'application/octet-stream') {
// Append to $attachment array
$this->attachment[] = array(
@@ -2017,6 +2242,10 @@ public function InlineImageExists() {
return false;
}
+ /**
+ * Returns true if an attachment (non-inline) is present.
+ * @return bool
+ */
public function AttachmentExists() {
foreach($this->attachment as $attachment) {
if ($attachment[6] == 'attachment') {
@@ -2026,8 +2255,12 @@ public function AttachmentExists() {
return false;
}
+ /**
+ * Does this message have an alternative body set?
+ * @return bool
+ */
public function AlternativeExists() {
- return strlen($this->AltBody)>0;
+ return !empty($this->AltBody);
}
/////////////////////////////////////////////////
@@ -2111,6 +2344,7 @@ public function ClearCustomHeaders() {
/**
* Adds the error message to the error container.
* @access protected
+ * @param string $msg
* @return void
*/
protected function SetError($msg) {
@@ -2160,6 +2394,7 @@ protected function ServerHostname() {
/**
* Returns a message in the appropriate language.
* @access protected
+ * @param string $key
* @return string
*/
protected function Lang($key) {
@@ -2184,30 +2419,44 @@ public function IsError() {
}
/**
- * Changes every end of line from CR or LF to CRLF.
+ * Changes every end of line from CRLF, CR or LF to $this->LE.
* @access public
+ * @param string $str String to FixEOL
* @return string
*/
public function FixEOL($str) {
- $str = str_replace("\r\n", "\n", $str);
- $str = str_replace("\r", "\n", $str);
- $str = str_replace("\n", $this->LE, $str);
- return $str;
+ // condense down to \n
+ $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
+ // Now convert LE as needed
+ if ($this->LE !== "\n") {
+ $nstr = str_replace("\n", $this->LE, $nstr);
+ }
+ return $nstr;
}
/**
- * Adds a custom header.
+ * Adds a custom header. $name value can be overloaded to contain
+ * both header name and value (name:value)
* @access public
+ * @param string $name custom header name
+ * @param string $value header value
* @return void
*/
- public function AddCustomHeader($custom_header) {
- $this->CustomHeader[] = explode(':', $custom_header, 2);
+ public function AddCustomHeader($name, $value=null) {
+ if ($value === null) {
+ // Value passed in as name:value
+ $this->CustomHeader[] = explode(':', $name, 2);
+ } else {
+ $this->CustomHeader[] = array($name, $value);
+ }
}
/**
* Evaluates the message and returns modifications for inline images and backgrounds
* @access public
- * @return $message
+ * @param string $message Text to be HTML modified
+ * @param string $basedir baseline directory for path
+ * @return string $message
*/
public function MsgHTML($message, $basedir = '') {
preg_match_all("/(src|background)=[\"'](.*)[\"']/Ui", $message, $images);
@@ -2217,7 +2466,9 @@ public function MsgHTML($message, $basedir = '') {
if (!preg_match('#^[A-z]+://#', $url)) {
$filename = basename($url);
$directory = dirname($url);
- ($directory == '.') ? $directory='': '';
+ if ($directory == '.') {
+ $directory = '';
+ }
$cid = 'cid:' . md5($filename);
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$mimeType = self::_mime_types($ext);
@@ -2231,40 +2482,42 @@ public function MsgHTML($message, $basedir = '') {
}
$this->IsHTML(true);
$this->Body = $message;
- if (empty($this->AltBody)) {
- $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
- if (!empty($textMsg)) {
- $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet);
- }
- }
+ if (empty($this->AltBody)) {
+ $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
+ if (!empty($textMsg)) {
+ $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet);
+ }
+ }
if (empty($this->AltBody)) {
$this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
}
- return $message;
+ return $message;
}
/**
* Gets the MIME type of the embedded or inline image
- * @param string File extension
+ * @param string $ext File extension
* @access public
* @return string MIME type of ext
* @static
*/
public static function _mime_types($ext = '') {
$mimes = array(
+ 'xl' => 'application/excel',
'hqx' => 'application/mac-binhex40',
'cpt' => 'application/mac-compactpro',
- 'doc' => 'application/msword',
'bin' => 'application/macbinary',
+ 'doc' => 'application/msword',
+ 'word' => 'application/msword',
+ 'class' => 'application/octet-stream',
+ 'dll' => 'application/octet-stream',
'dms' => 'application/octet-stream',
+ 'exe' => 'application/octet-stream',
'lha' => 'application/octet-stream',
'lzh' => 'application/octet-stream',
- 'exe' => 'application/octet-stream',
- 'class' => 'application/octet-stream',
'psd' => 'application/octet-stream',
- 'so' => 'application/octet-stream',
'sea' => 'application/octet-stream',
- 'dll' => 'application/octet-stream',
+ 'so' => 'application/octet-stream',
'oda' => 'application/oda',
'pdf' => 'application/pdf',
'ai' => 'application/postscript',
@@ -2282,9 +2535,9 @@ public static function _mime_types($ext = '') {
'dxr' => 'application/x-director',
'dvi' => 'application/x-dvi',
'gtar' => 'application/x-gtar',
- 'php' => 'application/x-httpd-php',
- 'php4' => 'application/x-httpd-php',
'php3' => 'application/x-httpd-php',
+ 'php4' => 'application/x-httpd-php',
+ 'php' => 'application/x-httpd-php',
'phtml' => 'application/x-httpd-php',
'phps' => 'application/x-httpd-php-source',
'js' => 'application/x-javascript',
@@ -2292,69 +2545,68 @@ public static function _mime_types($ext = '') {
'sit' => 'application/x-stuffit',
'tar' => 'application/x-tar',
'tgz' => 'application/x-tar',
- 'xhtml' => 'application/xhtml+xml',
'xht' => 'application/xhtml+xml',
+ 'xhtml' => 'application/xhtml+xml',
'zip' => 'application/zip',
'mid' => 'audio/midi',
'midi' => 'audio/midi',
- 'mpga' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
'mp3' => 'audio/mpeg',
+ 'mpga' => 'audio/mpeg',
'aif' => 'audio/x-aiff',
- 'aiff' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
+ 'aiff' => 'audio/x-aiff',
'ram' => 'audio/x-pn-realaudio',
'rm' => 'audio/x-pn-realaudio',
'rpm' => 'audio/x-pn-realaudio-plugin',
'ra' => 'audio/x-realaudio',
- 'rv' => 'video/vnd.rn-realvideo',
'wav' => 'audio/x-wav',
'bmp' => 'image/bmp',
'gif' => 'image/gif',
'jpeg' => 'image/jpeg',
- 'jpg' => 'image/jpeg',
'jpe' => 'image/jpeg',
+ 'jpg' => 'image/jpeg',
'png' => 'image/png',
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
+ 'eml' => 'message/rfc822',
'css' => 'text/css',
'html' => 'text/html',
'htm' => 'text/html',
'shtml' => 'text/html',
- 'txt' => 'text/plain',
- 'text' => 'text/plain',
'log' => 'text/plain',
+ 'text' => 'text/plain',
+ 'txt' => 'text/plain',
'rtx' => 'text/richtext',
'rtf' => 'text/rtf',
'xml' => 'text/xml',
'xsl' => 'text/xml',
'mpeg' => 'video/mpeg',
- 'mpg' => 'video/mpeg',
'mpe' => 'video/mpeg',
- 'qt' => 'video/quicktime',
+ 'mpg' => 'video/mpeg',
'mov' => 'video/quicktime',
+ 'qt' => 'video/quicktime',
+ 'rv' => 'video/vnd.rn-realvideo',
'avi' => 'video/x-msvideo',
- 'movie' => 'video/x-sgi-movie',
- 'doc' => 'application/msword',
- 'word' => 'application/msword',
- 'xl' => 'application/excel',
- 'eml' => 'message/rfc822'
+ 'movie' => 'video/x-sgi-movie'
);
return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
}
/**
- * Set (or reset) Class Objects (variables)
- *
- * Usage Example:
- * $page->set('X-Priority', '3');
- *
- * @access public
- * @param string $name Parameter Name
- * @param mixed $value Parameter Value
- * NOTE: will not work with arrays, there are no arrays to set/reset
- * @todo Should this not be using __set() magic function?
- */
+ * Set (or reset) Class Objects (variables)
+ *
+ * Usage Example:
+ * $page->set('X-Priority', '3');
+ *
+ * @access public
+ * @param string $name Parameter Name
+ * @param mixed $value Parameter Value
+ * NOTE: will not work with arrays, there are no arrays to set/reset
+ * @throws phpmailerException
+ * @return bool
+ * @todo Should this not be using __set() magic function?
+ */
public function set($name, $value = '') {
try {
if (isset($this->$name) ) {
@@ -2378,15 +2630,14 @@ public function set($name, $value = '') {
* @return string
*/
public function SecureHeader($str) {
- $str = str_replace("\r", '', $str);
- $str = str_replace("\n", '', $str);
- return trim($str);
+ return trim(str_replace(array("\r", "\n"), '', $str));
}
/**
* Set the private key file and password to sign the message.
*
* @access public
+ * @param $cert_filename
* @param string $key_filename Parameter File Name
* @param string $key_pass Password for private key
*/
@@ -2400,11 +2651,10 @@ public function Sign($cert_filename, $key_filename, $key_pass) {
* Set the private key file and password to sign the message.
*
* @access public
- * @param string $key_filename Parameter File Name
- * @param string $key_pass Password for private key
+ * @param string $txt
+ * @return string
*/
public function DKIM_QP($txt) {
- $tmp = '';
$line = '';
for ($i = 0; $i < strlen($txt); $i++) {
$ord = ord($txt[$i]);
@@ -2422,6 +2672,7 @@ public function DKIM_QP($txt) {
*
* @access public
* @param string $s Header
+ * @return string
*/
public function DKIM_Sign($s) {
$privKeyStr = file_get_contents($this->DKIM_private);
@@ -2433,6 +2684,7 @@ public function DKIM_Sign($s) {
if (openssl_sign($s, $signature, $privKey)) {
return base64_encode($signature);
}
+ return '';
}
/**
@@ -2440,6 +2692,7 @@ public function DKIM_Sign($s) {
*
* @access public
* @param string $s Header
+ * @return string
*/
public function DKIM_HeaderC($s) {
$s = preg_replace("/\r\n\s+/", " ", $s);
@@ -2459,6 +2712,7 @@ public function DKIM_HeaderC($s) {
*
* @access public
* @param string $body Message Body
+ * @return string
*/
public function DKIM_BodyC($body) {
if ($body == '') return "\r\n";
@@ -2479,6 +2733,7 @@ public function DKIM_BodyC($body) {
* @param string $headers_line Header lines
* @param string $subject Subject
* @param string $body Body
+ * @return string
*/
public function DKIM_Add($headers_line, $subject, $body) {
$DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms
@@ -2487,6 +2742,8 @@ public function DKIM_Add($headers_line, $subject, $body) {
$DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
$subject_header = "Subject: $subject";
$headers = explode($this->LE, $headers_line);
+ $from_header = "";
+ $to_header = "";
foreach($headers as $header) {
if (strpos($header, 'From:') === 0) {
$from_header = $header;
@@ -2512,21 +2769,38 @@ public function DKIM_Add($headers_line, $subject, $body) {
"\tb=";
$toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs);
$signed = $this->DKIM_Sign($toSign);
- return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n";
+ return "X-PHPMAILER-DKIM: code.google.com/a/apache-extras.org/p/phpmailer/\r\n".$dkimhdrs.$signed."\r\n";
}
- protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) {
- if (!empty($this->action_function) && function_exists($this->action_function)) {
- $params = array($isSent, $to, $cc, $bcc, $subject, $body);
+ /**
+ * Perform callback
+ * @param boolean $isSent
+ * @param string $to
+ * @param string $cc
+ * @param string $bcc
+ * @param string $subject
+ * @param string $body
+ * @param string $from
+ */
+ protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from = null) {
+ if (!empty($this->action_function) && is_callable($this->action_function)) {
+ $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
call_user_func_array($this->action_function, $params);
}
}
}
+/**
+ * Exception handler for PHPMailer
+ * @package PHPMailer
+ */
class phpmailerException extends Exception {
+ /**
+ * Prettify error message output
+ * @return string
+ */
public function errorMessage() {
$errorMsg = '' . $this->getMessage() . "
\n";
return $errorMsg;
}
}
-?>
diff --git a/class.pop3.php b/class.pop3.php
index adde15fba..891b99562 100644
--- a/class.pop3.php
+++ b/class.pop3.php
@@ -2,7 +2,7 @@
/*~ class.pop3.php
.---------------------------------------------------------------------------.
| Software: PHPMailer - PHP email class |
-| Version: 5.2.1 |
+| Version: 5.2.2 |
| Site: https://code.google.com/a/apache-extras.org/p/phpmailer/ |
| ------------------------------------------------------------------------- |
| Admin: Jim Jagielski (project admininistrator) |
@@ -32,19 +32,17 @@
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
- * @version $Id: class.pop3.php 450 2010-06-23 16:46:33Z coolbru $
*/
/**
- * POP Before SMTP Authentication Class
- * Version 5.2.1
+ * PHP POP-Before-SMTP Authentication Class
*
- * Author: Richard Davey (rich@corephp.co.uk)
- * Modifications: Andy Prevost
- * License: LGPL, see PHPMailer License
+ * Version 5.2.2
+ *
+ * @license: LGPL, see PHPMailer License
*
* Specifically for PHPMailer to allow POP before SMTP authentication.
- * Does not yet work with APOP - if you have an APOP account, contact Richard Davey
+ * Does not yet work with APOP - if you have an APOP account, contact Jim Jagielski
* and we can test changes to this script.
*
* This class is based on the structure of the SMTP class originally authored by Chris Ryan
@@ -53,7 +51,9 @@
* required for POP3 connection, authentication and disconnection.
*
* @package PHPMailer
- * @author Richard Davey
+ * @author Richard Davey (orig)
+ * @author Andy Prevost
+ * @author Jim Jagielski
*/
class POP3 {
@@ -115,14 +115,23 @@ class POP3 {
* Sets the POP3 PHPMailer Version number
* @var string
*/
- public $Version = '5.2.1';
+ public $Version = '5.2.2-rc2';
/////////////////////////////////////////////////
// PROPERTIES, PRIVATE AND PROTECTED
/////////////////////////////////////////////////
+ /**
+ * @var resource Resource handle for the POP connection socket
+ */
private $pop_conn;
+ /**
+ * @var boolean Are we connected?
+ */
private $connected;
+ /**
+ * @var array Error container
+ */
private $error; // Error log array
/**
@@ -140,10 +149,12 @@ public function __construct() {
* Combination of public events - connect, login, disconnect
* @access public
* @param string $host
- * @param integer $port
- * @param integer $tval
+ * @param bool|int $port
+ * @param bool|int $tval
* @param string $username
* @param string $password
+ * @param int $debug_level
+ * @return bool
*/
public function Authorise ($host, $port = false, $tval = false, $username, $password, $debug_level = 0) {
$this->host = $host;
@@ -193,7 +204,7 @@ public function Authorise ($host, $port = false, $tval = false, $username, $pass
* Connect to the POP3 server
* @access public
* @param string $host
- * @param integer $port
+ * @param bool|int $port
* @param integer $tval
* @return boolean
*/
@@ -258,11 +269,11 @@ public function Connect ($host, $port = false, $tval = 30) {
// Check for the +OK
if ($this->checkResponse($pop3_response)) {
- // The connection is established and the POP3 server is talking
- $this->connected = true;
+ // The connection is established and the POP3 server is talking
+ $this->connected = true;
return true;
}
-
+ return false;
}
/**
@@ -303,12 +314,9 @@ public function Login ($username = '', $password = '') {
if ($this->checkResponse($pop3_response)) {
return true;
- } else {
- return false;
}
- } else {
- return false;
}
+ return false;
}
/**
@@ -407,4 +415,3 @@ private function catchWarning ($errno, $errstr, $errfile, $errline) {
// End of class
}
-?>
diff --git a/class.smtp.php b/class.smtp.php
index 6977bffad..e5d86bc17 100644
--- a/class.smtp.php
+++ b/class.smtp.php
@@ -36,11 +36,12 @@
*/
/**
- * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
- * commands except TURN which will always return a not implemented
- * error. SMTP also provides some utility methods for sending mail
- * to an SMTP server.
- * original author: Chris Ryan
+ * PHP RFC821 SMTP client
+ *
+ * Implements all the RFC 821 SMTP commands except TURN which will always return a not implemented error.
+ * SMTP also provides some utility methods for sending mail to an SMTP server.
+ * @author Chris Ryan
+ * @package PHPMailer
*/
class SMTP {
@@ -51,7 +52,7 @@ class SMTP {
public $SMTP_PORT = 25;
/**
- * SMTP reply line ending
+ * SMTP reply line ending (don't change)
* @var string
*/
public $CRLF = "\r\n";
@@ -62,30 +63,70 @@ class SMTP {
*/
public $do_debug; // the level of debug to perform
+ /**
+ * Sets the function/method to use for debugging output.
+ * Right now we only honor "echo" or "error_log"
+ * @var string
+ */
+ public $Debugoutput = "echo";
+
/**
* Sets VERP use on/off (default is off)
* @var bool
*/
public $do_verp = false;
+ /**
+ * Sets the SMTP timeout value for reads, in seconds
+ * @var int
+ */
+ public $Timeout = 15;
+
+ /**
+ * Sets the SMTP timelimit value for reads, in seconds
+ * @var int
+ */
+ public $Timelimit = 30;
+
/**
* Sets the SMTP PHPMailer Version number
* @var string
*/
- public $Version = '5.2.1';
+ public $Version = '5.2.2-rc2';
/////////////////////////////////////////////////
// PROPERTIES, PRIVATE AND PROTECTED
/////////////////////////////////////////////////
- private $smtp_conn; // the socket to the server
- private $error; // error if any on the last call
- private $helo_rply; // the reply the server sent to us for HELO
+ /**
+ * @var resource The socket to the server
+ */
+ private $smtp_conn;
+ /**
+ * @var string Error message, if any, for the last call
+ */
+ private $error;
+ /**
+ * @var string The reply the server sent to us for HELO
+ */
+ private $helo_rply;
+
+ /**
+ * Outputs debugging info via user-defined method
+ * @param string $str
+ */
+ private function edebug($str) {
+ if ($this->Debugoutput == "error_log") {
+ error_log($str);
+ } else {
+ echo $str;
+ }
+ }
/**
* Initialize the class so that the data is in a known state.
* @access public
- * @return void
+ * @return SMTP
*/
public function __construct() {
$this->smtp_conn = 0;
@@ -110,6 +151,9 @@ public function __construct() {
* SMTP CODE SUCCESS: 220
* SMTP CODE FAILURE: 421
* @access public
+ * @param string $host
+ * @param int $port
+ * @param int $tval
* @return bool
*/
public function Connect($host, $port = 0, $tval = 30) {
@@ -139,21 +183,26 @@ public function Connect($host, $port = 0, $tval = 30) {
"errno" => $errno,
"errstr" => $errstr);
if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '
';
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '
');
}
return false;
}
// SMTP server can take longer to respond, give longer timeout for first read
// Windows does not have support for this timeout function
- if(substr(PHP_OS, 0, 3) != "WIN")
- socket_set_timeout($this->smtp_conn, $tval, 0);
+ if(substr(PHP_OS, 0, 3) != "WIN") {
+ $max = ini_get('max_execution_time');
+ if ($max != 0 && $tval > $max) { // don't bother if unlimited
+ @set_time_limit($tval);
+ }
+ stream_set_timeout($this->smtp_conn, $tval, 0);
+ }
// get any announcement
$announce = $this->get_lines();
if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '
';
+ $this->edebug("SMTP -> FROM SERVER:" . $announce . $this->CRLF . '
');
}
return true;
@@ -182,7 +231,7 @@ public function StartTLS() {
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
');
}
if($code != 220) {
@@ -191,7 +240,7 @@ public function StartTLS() {
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
');
}
return false;
}
@@ -208,60 +257,164 @@ public function StartTLS() {
* Performs SMTP authentication. Must be run after running the
* Hello() method. Returns true if successfully authenticated.
* @access public
+ * @param string $username
+ * @param string $password
+ * @param string $authtype
+ * @param string $realm
+ * @param string $workstation
* @return bool
*/
- public function Authenticate($username, $password) {
- // Start authentication
- fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
+ public function Authenticate($username, $password, $authtype='LOGIN', $realm='', $workstation='') {
+ if (empty($authtype)) {
+ $authtype = 'LOGIN';
+ }
+
+ switch ($authtype) {
+ case 'PLAIN':
+ // Start authentication
+ fputs($this->smtp_conn,"AUTH PLAIN" . $this->CRLF);
+
+ $rply = $this->get_lines();
+ $code = substr($rply,0,3);
+
+ if($code != 334) {
+ $this->error =
+ array("error" => "AUTH not accepted from server",
+ "smtp_code" => $code,
+ "smtp_msg" => substr($rply,4));
+ if($this->do_debug >= 1) {
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
');
+ }
+ return false;
+ }
+ // Send encoded username and password
+ fputs($this->smtp_conn, base64_encode("\0".$username."\0".$password) . $this->CRLF);
+
+ $rply = $this->get_lines();
+ $code = substr($rply,0,3);
+
+ if($code != 235) {
+ $this->error =
+ array("error" => "Authentication not accepted from server",
+ "smtp_code" => $code,
+ "smtp_msg" => substr($rply,4));
+ if($this->do_debug >= 1) {
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
');
+ }
+ return false;
+ }
+ break;
+ case 'LOGIN':
+ // Start authentication
+ fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
+
+ $rply = $this->get_lines();
+ $code = substr($rply,0,3);
+
+ if($code != 334) {
+ $this->error =
+ array("error" => "AUTH not accepted from server",
+ "smtp_code" => $code,
+ "smtp_msg" => substr($rply,4));
+ if($this->do_debug >= 1) {
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
');
+ }
+ return false;
+ }
- $rply = $this->get_lines();
- $code = substr($rply,0,3);
+ // Send encoded username
+ fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
- if($code != 334) {
- $this->error =
- array("error" => "AUTH not accepted from server",
- "smtp_code" => $code,
- "smtp_msg" => substr($rply,4));
- if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
- }
- return false;
- }
+ $rply = $this->get_lines();
+ $code = substr($rply,0,3);
- // Send encoded username
- fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
+ if($code != 334) {
+ $this->error =
+ array("error" => "Username not accepted from server",
+ "smtp_code" => $code,
+ "smtp_msg" => substr($rply,4));
+ if($this->do_debug >= 1) {
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
');
+ }
+ return false;
+ }
- $rply = $this->get_lines();
- $code = substr($rply,0,3);
+ // Send encoded password
+ fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
- if($code != 334) {
- $this->error =
- array("error" => "Username not accepted from server",
- "smtp_code" => $code,
- "smtp_msg" => substr($rply,4));
- if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
- }
- return false;
- }
+ $rply = $this->get_lines();
+ $code = substr($rply,0,3);
- // Send encoded password
- fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
+ if($code != 235) {
+ $this->error =
+ array("error" => "Password not accepted from server",
+ "smtp_code" => $code,
+ "smtp_msg" => substr($rply,4));
+ if($this->do_debug >= 1) {
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
');
+ }
+ return false;
+ }
+ break;
+ case 'NTLM':
+ /*
+ * ntlm_sasl_client.php
+ ** Bundled with Permission
+ **
+ ** How to telnet in windows: http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx
+ ** PROTOCOL Documentation http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication
+ */
+ require_once('ntlm_sasl_client.php');
+ $temp = new stdClass();
+ $ntlm_client = new ntlm_sasl_client_class;
+ if(! $ntlm_client->Initialize($temp)){//let's test if every function its available
+ $this->error = array("error" => $temp->error);
+ if($this->do_debug >= 1) {
+ $this->edebug("You need to enable some modules in your php.ini file: " . $this->error["error"] . $this->CRLF);
+ }
+ return false;
+ }
+ $msg1 = $ntlm_client->TypeMsg1($realm, $workstation);//msg1
- $rply = $this->get_lines();
- $code = substr($rply,0,3);
+ fputs($this->smtp_conn,"AUTH NTLM " . base64_encode($msg1) . $this->CRLF);
+
+ $rply = $this->get_lines();
+ $code = substr($rply,0,3);
- if($code != 235) {
- $this->error =
- array("error" => "Password not accepted from server",
- "smtp_code" => $code,
- "smtp_msg" => substr($rply,4));
- if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
- }
- return false;
- }
+ if($code != 334) {
+ $this->error =
+ array("error" => "AUTH not accepted from server",
+ "smtp_code" => $code,
+ "smtp_msg" => substr($rply,4));
+ if($this->do_debug >= 1) {
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
+ }
+ return false;
+ }
+
+ $challange = substr($rply,3);//though 0 based, there is a white space after the 3 digit number....//msg2
+ $challange = base64_decode($challange);
+ $ntlm_res = $ntlm_client->NTLMResponse(substr($challange,24,8),$password);
+ $msg3 = $ntlm_client->TypeMsg3($ntlm_res,$username,$realm,$workstation);//msg3
+ // Send encoded username
+ fputs($this->smtp_conn, base64_encode($msg3) . $this->CRLF);
+
+ $rply = $this->get_lines();
+ $code = substr($rply,0,3);
+
+ if($code != 235) {
+ $this->error =
+ array("error" => "Could not authenticate",
+ "smtp_code" => $code,
+ "smtp_msg" => substr($rply,4));
+ if($this->do_debug >= 1) {
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
+ }
+ return false;
+ }
+ break;
+ }
return true;
}
@@ -276,7 +429,7 @@ public function Connected() {
if($sock_status["eof"]) {
// the socket is valid but we are not connected
if($this->do_debug >= 1) {
- echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
+ $this->edebug("SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected");
}
$this->Close();
return false;
@@ -324,6 +477,7 @@ public function Close() {
* SMTP CODE FAILURE: 451,554
* SMTP CODE ERROR : 500,501,503,421
* @access public
+ * @param string $msg_data
* @return bool
*/
public function Data($msg_data) {
@@ -341,7 +495,7 @@ public function Data($msg_data) {
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
');
}
if($code != 354) {
@@ -350,7 +504,7 @@ public function Data($msg_data) {
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
');
}
return false;
}
@@ -435,7 +589,7 @@ public function Data($msg_data) {
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
');
}
if($code != 250) {
@@ -444,7 +598,7 @@ public function Data($msg_data) {
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
');
}
return false;
}
@@ -461,6 +615,7 @@ public function Data($msg_data) {
* SMTP CODE SUCCESS: 250
* SMTP CODE ERROR : 500, 501, 504, 421
* @access public
+ * @param string $host
* @return bool
*/
public function Hello($host = '') {
@@ -491,6 +646,8 @@ public function Hello($host = '') {
/**
* Sends a HELO/EHLO command.
* @access private
+ * @param string $hello
+ * @param string $host
* @return bool
*/
private function SendHello($hello, $host) {
@@ -500,7 +657,7 @@ private function SendHello($hello, $host) {
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> FROM SERVER: " . $rply . $this->CRLF . '
');
}
if($code != 250) {
@@ -509,7 +666,7 @@ private function SendHello($hello, $host) {
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
');
}
return false;
}
@@ -531,6 +688,7 @@ private function SendHello($hello, $host) {
* SMTP CODE SUCCESS: 552,451,452
* SMTP CODE SUCCESS: 500,501,421
* @access public
+ * @param string $from
* @return bool
*/
public function Mail($from) {
@@ -542,14 +700,14 @@ public function Mail($from) {
return false;
}
- $useVerp = ($this->do_verp ? "XVERP" : "");
+ $useVerp = ($this->do_verp ? " XVERP" : "");
fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
');
}
if($code != 250) {
@@ -558,7 +716,7 @@ public function Mail($from) {
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
');
}
return false;
}
@@ -574,6 +732,7 @@ public function Mail($from) {
* SMTP CODE SUCCESS: 221
* SMTP CODE ERROR : 500
* @access public
+ * @param bool $close_on_error
* @return bool
*/
public function Quit($close_on_error = true) {
@@ -592,7 +751,7 @@ public function Quit($close_on_error = true) {
$byemsg = $this->get_lines();
if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '
';
+ $this->edebug("SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '
');
}
$rval = true;
@@ -606,7 +765,7 @@ public function Quit($close_on_error = true) {
"smtp_rply" => substr($byemsg,4));
$rval = false;
if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '
';
+ $this->edebug("SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '
');
}
}
@@ -627,6 +786,7 @@ public function Quit($close_on_error = true) {
* SMTP CODE FAILURE: 550,551,552,553,450,451,452
* SMTP CODE ERROR : 500,501,503,421
* @access public
+ * @param string $to
* @return bool
*/
public function Recipient($to) {
@@ -644,7 +804,7 @@ public function Recipient($to) {
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
');
}
if($code != 250 && $code != 251) {
@@ -653,7 +813,7 @@ public function Recipient($to) {
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
');
}
return false;
}
@@ -687,7 +847,7 @@ public function Reset() {
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
');
}
if($code != 250) {
@@ -696,7 +856,7 @@ public function Reset() {
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
');
}
return false;
}
@@ -718,6 +878,7 @@ public function Reset() {
* SMTP CODE SUCCESS: 552,451,452
* SMTP CODE SUCCESS: 500,501,502,421
* @access public
+ * @param string $from
* @return bool
*/
public function SendAndMail($from) {
@@ -735,7 +896,7 @@ public function SendAndMail($from) {
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '
');
}
if($code != 250) {
@@ -744,7 +905,7 @@ public function SendAndMail($from) {
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
';
+ $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '
');
}
return false;
}
@@ -768,7 +929,7 @@ public function Turn() {
$this->error = array("error" => "This method, TURN, of the SMTP ".
"is not implemented");
if($this->do_debug >= 1) {
- echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '
';
+ $this->edebug("SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '
');
}
return false;
}
@@ -797,22 +958,46 @@ public function getError() {
*/
private function get_lines() {
$data = "";
- while(!feof($this->smtp_conn)) {
+ $endtime = 0;
+ /* If for some reason the fp is bad, don't inf loop */
+ if (!is_resource($this->smtp_conn)) {
+ return $data;
+ }
+ stream_set_timeout($this->smtp_conn, $this->Timeout);
+ if ($this->Timelimit > 0) {
+ $endtime = time() + $this->Timelimit;
+ }
+ while(is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
$str = @fgets($this->smtp_conn,515);
if($this->do_debug >= 4) {
- echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '
';
- echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '
';
+ $this->edebug("SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '
');
+ $this->edebug("SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '
');
}
$data .= $str;
if($this->do_debug >= 4) {
- echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '
';
+ $this->edebug("SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '
');
}
// if 4th character is a space, we are done reading, break the loop
if(substr($str,3,1) == " ") { break; }
+ // Timed-out? Log and break
+ $info = stream_get_meta_data($this->smtp_conn);
+ if ($info['timed_out']) {
+ if($this->do_debug >= 4) {
+ $this->edebug("SMTP -> get_lines(): timed-out (" . $this->Timeout . " seconds)
");
+ }
+ break;
+ }
+ // Now check if reads took too long
+ if ($endtime) {
+ if (time() > $endtime) {
+ if($this->do_debug >= 4) {
+ $this->edebug("SMTP -> get_lines(): timelimit reached (" . $this->Timelimit . " seconds)
");
+ }
+ break;
+ }
+ }
}
return $data;
}
}
-
-?>
diff --git a/docs.ini b/docs.ini
deleted file mode 100644
index 6906eb0d0..000000000
--- a/docs.ini
+++ /dev/null
@@ -1,92 +0,0 @@
-;; phpDocumentor parse configuration file
-;;
-;; This file is designed to cut down on repetitive typing on the command-line or web interface
-;; You can copy this file to create a number of configuration files that can be used with the
-;; command-line switch -c, as in phpdoc -c default.ini or phpdoc -c myini.ini. The web
-;; interface will automatically generate a list of .ini files that can be used.
-;;
-;; default.ini is used to generate the online manual at http://www.phpdoc.org/docs
-;;
-;; ALL .ini files must be in the user subdirectory of phpDocumentor with an extension of .ini
-;;
-;; Copyright 2002, Greg Beaver
-;;
-;; WARNING: do not change the name of any command-line parameters, phpDocumentor will ignore them
-
-[Parse Data]
-;; title of all the documentation
-;; legal values: any string
-title = PHPMailer Documentation
-
-;; parse files that start with a . like .bash_profile
-;; legal values: true, false
-hidden = false
-
-;; show elements marked @access private in documentation by setting this to on
-;; legal values: on, off
-parseprivate = on
-
-;; parse with javadoc-like description (first sentence is always the short description)
-;; legal values: on, off
-javadocdesc = off
-
-;; add any custom @tags separated by commas here
-;; legal values: any legal tagname separated by commas.
-;customtags = mytag1,mytag2
-
-;; This is only used by the XML:DocBook/peardoc2 converter
-defaultcategoryname = Documentation
-
-;; what is the main package?
-;; legal values: alphanumeric string plus - and _
-defaultpackagename = PHPMailer
-
-;; output any parsing information? set to on for cron jobs
-;; legal values: on
-;quiet = on
-
-;; parse a PEAR-style repository. Do not turn this on if your project does
-;; not have a parent directory named "pear"
-;; legal values: on/off
-;pear = on
-
-;; where should the documentation be written?
-;; legal values: a legal path
-target = ./phpdoc
-
-;; limit output to the specified packages, even if others are parsed
-;; legal values: package names separated by commas
-;packageoutput = package1,package2
-
-;; comma-separated list of files to parse
-;; legal values: paths separated by commas
-;filename = /path/to/file1,/path/to/file2,fileincurrentdirectory
-filename = *.php
-
-;; comma-separated list of directories to parse
-;; legal values: directory paths separated by commas
-;directory = /path1,/path2,.,..,subdirectory
-;directory = /home/jeichorn/cvs/pear
-;;directory = .
-
-;; template base directory (the equivalent directory of /phpDocumentor)
-;templatebase = /path/to/my/templates
-
-;; comma-separated list of files, directories or wildcards ? and * (any wildcard) to ignore
-;; legal values: any wildcard strings separated by commas
-;ignore = /path/to/ignore*,*list.php,myfile.php,subdirectory/
-ignore = templates_c/,*HTML/default/*,spec/,*CVS*,*.txt,docs/,phpdoc/,examples/,test/
-
-;; comma-separated list of Converters to use in outputformat:Convertername:templatedirectory format
-;; legal values: HTML:frames:default,HTML:frames:l0l33t,HTML:frames:phpdoc.de,HTML:frames:phphtmllib,
-;; HTML:frames:earthli,
-;; HTML:frames:DOM/default,HTML:frames:DOM/l0l33t,HTML:frames:DOM/phpdoc.de,
-;; HTML:frames:DOM/phphtmllib,HTML:frames:DOM/earthli
-;; HTML:Smarty:default,HTML:Smarty:PHP,HTML:Smarty:HandS
-;; PDF:default:default,CHM:default:default,XML:DocBook/peardoc2:default
-;;output=HTML:frames:earthli
-output=HTML:Smarty:HandS
-
-;; turn this option on if you want highlighted source code for every file
-;; legal values: on/off
-sourcecode = on
diff --git a/docs/Callback_function_notes.txt b/docs/Callback_function_notes.txt
new file mode 100644
index 000000000..461ea508e
--- /dev/null
+++ b/docs/Callback_function_notes.txt
@@ -0,0 +1,17 @@
+NEW CALLBACK FUNCTION:
+======================
+
+We have had requests for a method to process the results of sending emails
+through PHPMailer. In this new release, we have implemented a callback
+function that passes the results of each email sent (to, cc, and/or bcc).
+We have provided an example that echos the results back to the screen. The
+callback function can be used for any purpose. With minor modifications, the
+callback function can be used to create CSV logs, post results to databases,
+etc.
+
+Please review the test.php script for the example.
+
+It's pretty straight forward.
+
+Enjoy!
+Andy
diff --git a/docs/DomainKeys_notes.txt b/docs/DomainKeys_notes.txt
new file mode 100644
index 000000000..2ad10f159
--- /dev/null
+++ b/docs/DomainKeys_notes.txt
@@ -0,0 +1,55 @@
+CREATE DKIM KEYS and DNS Resource Record:
+=========================================
+
+To create DomainKeys Identified Mail keys, visit:
+http://dkim.worxware.com/
+... read the information, fill in the form, and download the ZIP file
+containing the public key, private key, DNS Resource Record and instructions
+to add to your DNS Zone Record, and the PHPMailer code to enable DKIM
+digital signing.
+
+/*** PROTECT YOUR PRIVATE & PUBLIC KEYS ***/
+
+You need to protect your DKIM private and public keys from being viewed or
+accessed. Add protection to your .htaccess file as in this example:
+
+# secure htkeyprivate file
+
+ order allow,deny
+ deny from all
+
+
+# secure htkeypublic file
+
+ order allow,deny
+ deny from all
+
+
+(the actual .htaccess additions are in the ZIP file sent back to you from
+http://dkim.worxware.com/
+
+A few notes on using DomainKey Identified Mail (DKIM):
+
+You do not need to use PHPMailer to DKIM sign emails IF:
+- you enable DomainKey support and add the DNS resource record
+- you use your outbound mail server
+
+If you are a third-party emailer that works on behalf of domain owners to
+send their emails from your own server:
+- you absolutely have to DKIM sign outbound emails
+- the domain owner has to add the DNS resource record to match the
+ private key, public key, selector, identity, and domain that you create
+- use caution with the "selector" ... at least one "selector" will already
+ exist in the DNS Zone Record of the domain at the domain owner's server
+ you need to ensure that the "selector" you use is unique
+Note: since the IP address will not match the domain owner's DNS Zone record
+you can be certain that email providers that validate based on DomainKey will
+check the domain owner's DNS Zone record for your DNS resource record. Before
+sending out emails on behalf of domain owners, ensure they have entered the
+DNS resource record you provided them.
+
+Enjoy!
+Andy
+
+PS. if you need additional information about DKIM, please see:
+http://www.dkim.org/info/dkim-faq.html
diff --git a/docs/Note_for_SMTP_debugging.txt b/docs/Note_for_SMTP_debugging.txt
new file mode 100644
index 000000000..afb5b58ef
--- /dev/null
+++ b/docs/Note_for_SMTP_debugging.txt
@@ -0,0 +1,23 @@
+If you are having problems connecting or sending emails through your SMTP server, please note:
+
+1. The new rewrite of class.smtp.php provides more information about the processing/errors taking place
+2. Use the debug functionality of class.smtp.php. To do that, in your own script add the debug level you wish to use. An example of that is:
+
+$mail->SMTPDebug = 1;
+$mail->IsSMTP(); // telling the class to use SMTP
+$mail->SMTPAuth = true; // enable SMTP authentication
+$mail->Port = 26; // set the SMTP port
+$mail->Host = "mail.yourhost.com"; // SMTP server
+$mail->Username = "name@yourhost.com"; // SMTP account username
+$mail->Password = "your password"; // SMTP account password
+
+Notes on this:
+$mail->SMTPDebug = 0; ... will disable debugging (you can also leave this out completely, 0 is the default
+$mail->SMTPDebug = 1; ... will echo errors and messages
+$mail->SMTPDebug = 2; ... will echo messages only
+... and finally, the options are 0, 1, and 2 ... any number greater than 2 will be interpreted as 2
+
+And finally, don't forget to disable debugging before going into production.
+
+Enjoy!
+Andy
\ No newline at end of file
diff --git a/docs/extending.html b/docs/extending.html
new file mode 100644
index 000000000..310f97a3b
--- /dev/null
+++ b/docs/extending.html
@@ -0,0 +1,148 @@
+
+
+Examples using phpmailer
+
+
+
+
+Examples using phpmailer
+
+1. Advanced Example
+
+
+This demonstrates sending out multiple email messages with binary attachments
+from a MySQL database with multipart/alternative support.
+
+
+
+
+require("class.phpmailer.php");
+
+$mail = new phpmailer();
+
+$mail->From = "list@example.com";
+$mail->FromName = "List manager";
+$mail->Host = "smtp1.example.com;smtp2.example.com";
+$mail->Mailer = "smtp";
+
+@MYSQL_CONNECT("localhost","root","password");
+@mysql_select_db("my_company");
+$query ="SELECT full_name, email,photoFROM employeeWHEREid=$id";
+$result=@MYSQL_QUERY($query);
+
+while ($row = mysql_fetch_array ($result))
+{
+ // HTML body
+ $body = "Hello <font size=\"4\">" . $row["full_name"] . "</font>, <p>";
+ $body .= "<i>Your</i> personal photograph to this message.<p>";
+ $body .= "Sincerely, <br>";
+ $body .= "phpmailer List manager";
+
+ // Plain text body (for mail clients that cannot read HTML)
+ $text_body = "Hello " . $row["full_name"] . ", \n\n";
+ $text_body .= "Your personal photograph to this message.\n\n";
+ $text_body .= "Sincerely, \n";
+ $text_body .= "phpmailer List manager";
+
+ $mail->Body = $body;
+ $mail->AltBody = $text_body;
+ $mail->AddAddress($row["email"], $row["full_name"]);
+ $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");
+
+ if(!$mail->Send())
+ echo "There has been a mail error sending to " . $row["email"] . "<br>";
+
+ // Clear all addresses and attachments for next loop
+ $mail->ClearAddresses();
+ $mail->ClearAttachments();
+}
+
+ |
+
+
+
+
+
2. Extending phpmailer
+
+
+Extending classes with inheritance is one of the most
+powerful features of object-oriented
+programming. It allows you to make changes to the
+original class for your
+own personal use without hacking the original
+classes. Plus, it is very
+easy to do. I've provided an example:
+
+
+Here's a class that extends the phpmailer class and sets the defaults
+for the particular site:
+PHP include file: mail.inc.php
+
+
+
+
+
+
+require("class.phpmailer.php");
+
+class my_phpmailer extends phpmailer {
+ // Set default variables for all new objects
+ var $From = "from@example.com";
+ var $FromName = "Mailer";
+ var $Host = "smtp1.example.com;smtp2.example.com";
+ var $Mailer = "smtp"; // Alternative to IsSMTP()
+ var $WordWrap = 75;
+
+ // Replace the default error_handler
+ function error_handler($msg) {
+ print("My Site Error");
+ print("Description:");
+ printf("%s", $msg);
+ exit;
+ }
+
+ // Create an additional function
+ function do_something($something) {
+ // Place your new code here
+ }
+}
+ |
+
+
+
+
+Now here's a normal PHP page in the site, which will have all the defaults set
+above:
+Normal PHP file: mail_test.php
+
+
+
+
+
+
+require("mail.inc.php");
+
+// Instantiate your new class
+$mail = new my_phpmailer;
+
+// Now you only need to add the necessary stuff
+$mail->AddAddress("josh@example.com", "Josh Adams");
+$mail->Subject = "Here is the subject";
+$mail->Body = "This is the message body";
+$mail->AddAttachment("c:/temp/11-10-00.zip", "new_name.zip"); // optional name
+
+if(!$mail->Send())
+{
+ echo "There was an error sending the message";
+ exit;
+}
+
+echo "Message was sent successfully";
+
+ |
+
+
+
+
+
+
diff --git a/docs/faq.html b/docs/faq.html
new file mode 100644
index 000000000..f71c6c892
--- /dev/null
+++ b/docs/faq.html
@@ -0,0 +1,67 @@
+
+
+PHPMailer FAQ
+
+
+
+
+
+
PHPMailer FAQ
+
+
+ - Q: I'm using the SMTP mailer and I keep on getting a timeout message
+ well before the X seconds I set it for. What gives?
+ A: PHP versions 4.0.4pl1 and earlier have a bug in which sockets timeout
+ early. You can fix this by re-compiling PHP 4.0.4pl1 with this fix:
+ timeoutfix.diff. Otherwise you can wait for the new PHP release.
+
+ - Q: I am concerned that using include files will take up too much
+ processing time on my computer. How can I make it run faster?
+ A: PHP by itself is very fast. Much faster than ASP or JSP running on
+ the same type of server. This is because it has very little overhead compared
+ to its competitors and it pre-compiles all of
+ its code before it runs each script (in PHP4). However, all of
+ this compiling and re-compiling can take up a lot of valuable
+ computer resources. However, there are programs out there that compile
+ PHP code and store it in memory (or on mmaped files) to reduce the
+ processing immensely. Two of these: APC
+ (Alternative PHP Cache) and Afterburner
+ (Win32 download)
+ are excellent free tools that do just this. If you have the money
+ you might also try Zend Cache, it is
+ even faster than the open source varieties. All of these tools make your
+ scripts run faster while also reducing the load on your server. I have tried
+ them myself and they are quite stable too.
+
+ - Q: What mailer gives me the best performance?
+ A: On a single machine the sendmail (or Qmail) is fastest overall.
+ Next fastest is mail() to give you the best performance. Both do not have the overhead of SMTP.
+ If you have you have your mail server on a another machine then
+ SMTP is your only option, but you do get the benefit of redundant mail servers.
+ If you are running a mailing list with thousands of names, the fastest mailers in order are: SMTP, sendmail (or Qmail), mail().
+
+ - Q: When I try to attach a file with on my server I get a
+ "Could not find {file} on filesystem error". Why is this?
+ A: If you are using a Unix machine this is probably because the user
+ running your web server does not have read access to the directory in question. If you are using Windows,
+ then the problem probably is that you have used single backslashes to denote directories (\).
+ A single backslash has a special meaning to PHP so these are not
+ valid. Instead use double backslashes ("\\") or a single forward
+ slash ("/").
+
+
+
+
+
+
+
+
diff --git a/docs/generatedocs.sh b/docs/generatedocs.sh
new file mode 100755
index 000000000..e4d690bf6
--- /dev/null
+++ b/docs/generatedocs.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+# Regenerate PHPMailer documentation
+rm -rf phpdocs/*
+phpdoc --directory .. --target ./phpdoc --ignore test/,examples/,extras/,test_script/ --sourcecode --force --title PHPMailer
diff --git a/docs/pop3_article.txt b/docs/pop3_article.txt
new file mode 100644
index 000000000..cc54f7c00
--- /dev/null
+++ b/docs/pop3_article.txt
@@ -0,0 +1,39 @@
+This is built for PHP Mailer 1.72 and was not tested with any previous version. It was developed under PHP 4.3.11 (E_ALL). It works under PHP 5 and 5.1 with E_ALL, but not in Strict mode due to var deprecation (but then neither does PHP Mailer either!). It follows the RFC 1939 standard explicitly and is fully commented.
+
+With that noted, here is how to implement it:
+Install the class file
+
+I didn't want to modify the PHP Mailer classes at all, so you will have to include/require this class along with the base one. It can sit quite happily in the phpmailer-1.72 directory:
+[geshi lang=php] require 'phpmailer-1.72/class.phpmailer.php'; require 'phpmailer-1.72/class.pop3.php'; [/geshi]
+When you need it, create your POP3 object
+
+Right before I invoke PHP Mailer I activate the POP3 authorisation. POP3 before SMTP is a process whereby you login to your web hosts POP3 mail server BEFORE sending out any emails via SMTP. The POP3 logon 'verifies' your ability to send email by SMTP, which typically otherwise blocks you. On my web host (Pair Networks) a single POP3 logon is enough to 'verify' you for 90 minutes. Here is some sample PHP code that activates the POP3 logon and then sends an email via PHP Mailer:
+[geshi lang=php] Authorise('pop3.example.com', 110, 30, 'mailer', 'password', 1); $mail = new PHPMailer(); $mail->SMTPDebug = 2; $mail->IsSMTP(); $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('rich@corephp.co.uk', 'Richard Davey'); if (!$mail->Send()) { echo $mail->ErrorInfo; } ?> [/geshi]
+
+The PHP Mailer parts of this code should be obvious to anyone who has used PHP Mailer before. One thing to note - you almost certainly will not need to use SMTP Authentication *and* POP3 before SMTP together. The Authorisation method is a proxy method to all of the others within that class. There are Connect, Logon and Disconnect methods available, but I wrapped them in the single Authorisation one to make things easier.
+The Parameters
+
+The Authorise parameters are as follows:
+[geshi lang=php]$pop->Authorise('pop3.example.com', 110, 30, 'mailer', 'password', 1);[/geshi]
+
+ 1. pop3.example.com - The POP3 Mail Server Name (hostname or IP address)
+ 2. 110 - The POP3 Port on which to connect (default is usually 110, but check with your host)
+ 3. 30 - A connection time-out value (in seconds)
+ 4. mailer - The POP3 Username required to logon
+ 5. password - The POP3 Password required to logon
+ 6. 1 - The class debug level (0 = off, 1+ = debug output is echoed to the browser)
+
+Final Comments + the Download
+
+1) This class does not support APOP connections. This is only because I did not have an APOP server to test with, but if you'd like to see that added just contact me.
+
+2) Opening and closing lots of POP3 connections can be quite a resource/network drain. If you need to send a whole batch of emails then just perform the authentication once at the start, and then loop through your mail sending script. Providing this process doesn't take longer than the verification period lasts on your POP3 server, you should be fine. With my host that period is 90 minutes, i.e. plenty of time.
+
+3) If you have heavy requirements for this script (i.e. send a LOT of email on a frequent basis) then I would advise seeking out an alternative sending method (direct SMTP ideally). If this isn't possible then you could modify this class so the 'last authorised' date is recorded somewhere (MySQL, Flat file, etc) meaning you only open a new connection if the old one has expired, saving you precious overhead.
+
+4) There are lots of other POP3 classes for PHP available. However most of them implement the full POP3 command set, where-as this one is purely for authentication, and much lighter as a result. However using any of the other POP3 classes to just logon to your server would have the same net result. At the end of the day, use whatever method you feel most comfortable with.
+Download
+
+Here is the full class file plus my test script: POP_before_SMTP_PHPMailer.zip (4 KB) - Please note that it does not include PHPMailer itself.
+
+My thanks to Chris Ryan for the inspiration (even if indirectly, via his SMTP class)
diff --git a/docs/use_gmail.txt b/docs/use_gmail.txt
new file mode 100644
index 000000000..2be1dffb5
--- /dev/null
+++ b/docs/use_gmail.txt
@@ -0,0 +1,44 @@
+IsSMTP();
+$mail->SMTPAuth = true; // enable SMTP authentication
+$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
+$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
+$mail->Port = 465; // set the SMTP port
+
+$mail->Username = "yourname@gmail.com"; // GMAIL username
+$mail->Password = "password"; // GMAIL password
+
+$mail->From = "replyto@yourdomain.com";
+$mail->FromName = "Webmaster";
+$mail->Subject = "This is the subject";
+$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
+$mail->WordWrap = 50; // set word wrap
+
+$mail->MsgHTML($body);
+
+$mail->AddReplyTo("replyto@yourdomain.com","Webmaster");
+
+$mail->AddAttachment("/path/to/file.zip"); // attachment
+$mail->AddAttachment("/path/to/image.jpg", "new.jpg"); // attachment
+
+$mail->AddAddress("username@domain.com","First Last");
+
+$mail->IsHTML(true); // send as HTML
+
+if(!$mail->Send()) {
+ echo "Mailer Error: " . $mail->ErrorInfo;
+} else {
+ echo "Message has been sent";
+}
+
+?>
diff --git a/examples/index.html b/examples/index.html
index c829bbcc7..08c808e59 100644
--- a/examples/index.html
+++ b/examples/index.html
@@ -21,7 +21,8 @@
the use of $mail->AltBody is completely optional. If not used, PHPMailer
will use the HTML text with htmlentities().
We also highly recommend using HTML2Text authored by Jon Abernathy. The class description
- and download can be viewed at: http://www.chuggnutt.com/html2text.php.
+ and download can be viewed at: http://www.chuggnutt.com/html2text but is also bundled with
+ PHPMailer in ./extras/ .
there is no specific code to define image or attachment types ... that is handled
automatically by PHPMailer when it parses the images
diff --git a/examples/test_db_smtp_basic.php b/examples/test_db_smtp_basic.php
index 9c16fb0bf..4e3c5418e 100644
--- a/examples/test_db_smtp_basic.php
+++ b/examples/test_db_smtp_basic.php
@@ -17,7 +17,7 @@
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
-$body = eregi_replace("[\]",'',$body);
+$body = preg_replace('/[\]/','',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp1.site.com;smtp2.site.com";
diff --git a/examples/test_mail_advanced.php b/examples/test_mail_advanced.php
index 38e27902d..8fbb702d6 100644
--- a/examples/test_mail_advanced.php
+++ b/examples/test_mail_advanced.php
@@ -10,7 +10,6 @@
$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
try {
- $mail->AddReplyTo('name@yourdomain.com', 'First Last');
$mail->AddAddress('whoto@otherdomain.com', 'John Doe');
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo('name@yourdomain.com', 'First Last');
diff --git a/examples/test_mail_basic.php b/examples/test_mail_basic.php
index f8411fb00..e20a2b343 100644
--- a/examples/test_mail_basic.php
+++ b/examples/test_mail_basic.php
@@ -11,9 +11,7 @@
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
-$body = eregi_replace("[\]",'',$body);
-
-$mail->AddReplyTo("name@yourdomain.com","First Last");
+$body = preg_replace('/[\]/','',$body);
$mail->SetFrom('name@yourdomain.com', 'First Last');
diff --git a/examples/test_pop_before_smtp_advanced.php b/examples/test_pop_before_smtp_advanced.php
index ee9d839eb..2c127edef 100644
--- a/examples/test_pop_before_smtp_advanced.php
+++ b/examples/test_pop_before_smtp_advanced.php
@@ -18,7 +18,6 @@
try {
$mail->SMTPDebug = 2;
$mail->Host = 'pop3.yourdomain.com';
- $mail->AddReplyTo('name@yourdomain.com', 'First Last');
$mail->AddAddress('whoto@otherdomain.com', 'John Doe');
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo('name@yourdomain.com', 'First Last');
diff --git a/examples/test_pop_before_smtp_basic.php b/examples/test_pop_before_smtp_basic.php
index f01bd824e..954bea8d4 100644
--- a/examples/test_pop_before_smtp_basic.php
+++ b/examples/test_pop_before_smtp_basic.php
@@ -14,7 +14,7 @@
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
-$body = eregi_replace("[\]",'',$body);
+$body = preg_replace('/[\]/','',$body);
$mail->IsSMTP();
$mail->SMTPDebug = 2;
diff --git a/examples/test_sendmail_advanced.php b/examples/test_sendmail_advanced.php
index 937d31e8e..7f31bcc70 100644
--- a/examples/test_sendmail_advanced.php
+++ b/examples/test_sendmail_advanced.php
@@ -12,7 +12,6 @@
$mail->IsSendmail(); // telling the class to use SendMail transport
try {
- $mail->AddReplyTo('name@yourdomain.com', 'First Last');
$mail->AddAddress('whoto@otherdomain.com', 'John Doe');
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo('name@yourdomain.com', 'First Last');
diff --git a/examples/test_sendmail_basic.php b/examples/test_sendmail_basic.php
index f70b0f062..0d8701f02 100644
--- a/examples/test_sendmail_basic.php
+++ b/examples/test_sendmail_basic.php
@@ -13,9 +13,7 @@
$mail->IsSendmail(); // telling the class to use SendMail transport
$body = file_get_contents('contents.html');
-$body = eregi_replace("[\]",'',$body);
-
-$mail->AddReplyTo("name@yourdomain.com","First Last");
+$body = preg_replace('/[\]/','',$body);
$mail->SetFrom('name@yourdomain.com', 'First Last');
diff --git a/examples/test_smtp_advanced.php b/examples/test_smtp_advanced.php
index 9013c8a46..70c76ecae 100644
--- a/examples/test_smtp_advanced.php
+++ b/examples/test_smtp_advanced.php
@@ -21,7 +21,6 @@
$mail->Port = 26; // set the SMTP port for the GMAIL server
$mail->Username = "yourname@yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
- $mail->AddReplyTo('name@yourdomain.com', 'First Last');
$mail->AddAddress('whoto@otherdomain.com', 'John Doe');
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo('name@yourdomain.com', 'First Last');
diff --git a/examples/test_smtp_advanced_no_auth.php b/examples/test_smtp_advanced_no_auth.php
index 101d2e2b8..75ce060f3 100644
--- a/examples/test_smtp_advanced_no_auth.php
+++ b/examples/test_smtp_advanced_no_auth.php
@@ -15,7 +15,6 @@
try {
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
- $mail->AddReplyTo('name@yourdomain.com', 'First Last');
$mail->AddAddress('whoto@otherdomain.com', 'John Doe');
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo('name@yourdomain.com', 'First Last');
diff --git a/examples/test_smtp_basic.php b/examples/test_smtp_basic.php
index 145f2acf3..cefa7007c 100644
--- a/examples/test_smtp_basic.php
+++ b/examples/test_smtp_basic.php
@@ -17,7 +17,7 @@
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
-$body = eregi_replace("[\]",'',$body);
+$body = preg_replace('/[\]/','',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
diff --git a/examples/test_smtp_basic_no_auth.php b/examples/test_smtp_basic_no_auth.php
index fe72ffa97..ca95c3dd5 100644
--- a/examples/test_smtp_basic_no_auth.php
+++ b/examples/test_smtp_basic_no_auth.php
@@ -17,7 +17,7 @@
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
-$body = eregi_replace("[\]",'',$body);
+$body = preg_replace('/[\]/','',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
diff --git a/examples/test_smtp_gmail_advanced.php b/examples/test_smtp_gmail_advanced.php
index 10d986073..80b26e0cc 100644
--- a/examples/test_smtp_gmail_advanced.php
+++ b/examples/test_smtp_gmail_advanced.php
@@ -21,7 +21,6 @@
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "yourusername@gmail.com"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password
- $mail->AddReplyTo('name@yourdomain.com', 'First Last');
$mail->AddAddress('whoto@otherdomain.com', 'John Doe');
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo('name@yourdomain.com', 'First Last');
diff --git a/examples/test_smtp_gmail_basic.php b/examples/test_smtp_gmail_basic.php
index abe22c52a..498078339 100644
--- a/examples/test_smtp_gmail_basic.php
+++ b/examples/test_smtp_gmail_basic.php
@@ -17,7 +17,7 @@
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
-$body = eregi_replace("[\]",'',$body);
+$body = preg_replace('/[\]/','',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
diff --git a/extras/class.html2text.inc b/extras/class.html2text.inc
new file mode 100644
index 000000000..56c486ca7
--- /dev/null
+++ b/extras/class.html2text.inc
@@ -0,0 +1,489 @@
+ *
+ * All rights reserved. *
+ * *
+ * This script is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * The GNU General Public License can be found at *
+ * http://www.gnu.org/copyleft/gpl.html. *
+ * *
+ * This script is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * Author(s): Jon Abernathy *
+ * *
+ * Last modified: 08/08/07 *
+ * *
+ *************************************************************************/
+
+
+/**
+ * Takes HTML and converts it to formatted, plain text.
+ *
+ * Thanks to Alexander Krug (http://www.krugar.de/) to pointing out and
+ * correcting an error in the regexp search array. Fixed 7/30/03.
+ *
+ * Updated set_html() function's file reading mechanism, 9/25/03.
+ *
+ * Thanks to Joss Sanglier (http://www.dancingbear.co.uk/) for adding
+ * several more HTML entity codes to the $search and $replace arrays.
+ * Updated 11/7/03.
+ *
+ * Thanks to Darius Kasperavicius (http://www.dar.dar.lt/) for
+ * suggesting the addition of $allowed_tags and its supporting function
+ * (which I slightly modified). Updated 3/12/04.
+ *
+ * Thanks to Justin Dearing for pointing out that a replacement for the
+ * tag was missing, and suggesting an appropriate fix.
+ * Updated 8/25/04.
+ *
+ * Thanks to Mathieu Collas (http://www.myefarm.com/) for finding a
+ * display/formatting bug in the _build_link_list() function: email
+ * readers would show the left bracket and number ("[1") as part of the
+ * rendered email address.
+ * Updated 12/16/04.
+ *
+ * Thanks to Wojciech Bajon (http://histeria.pl/) for submitting code
+ * to handle relative links, which I hadn't considered. I modified his
+ * code a bit to handle normal HTTP links and MAILTO links. Also for
+ * suggesting three additional HTML entity codes to search for.
+ * Updated 03/02/05.
+ *
+ * Thanks to Jacob Chandler for pointing out another link condition
+ * for the _build_link_list() function: "https".
+ * Updated 04/06/05.
+ *
+ * Thanks to Marc Bertrand (http://www.dresdensky.com/) for
+ * suggesting a revision to the word wrapping functionality; if you
+ * specify a $width of 0 or less, word wrapping will be ignored.
+ * Updated 11/02/06.
+ *
+ * *** Big housecleaning updates below:
+ *
+ * Thanks to Colin Brown (http://www.sparkdriver.co.uk/) for
+ * suggesting the fix to handle and blank lines (whitespace).
+ * Christian Basedau (http://www.movetheweb.de/) also suggested the
+ * blank lines fix.
+ *
+ * Special thanks to Marcus Bointon (http://www.synchromedia.co.uk/),
+ * Christian Basedau, Norbert Laposa (http://ln5.co.uk/),
+ * Bas van de Weijer, and Marijn van Butselaar
+ * for pointing out my glaring error in the | handling. Marcus also
+ * supplied a host of fixes.
+ *
+ * Thanks to Jeffrey Silverman (http://www.newtnotes.com/) for pointing
+ * out that extra spaces should be compressed--a problem addressed with
+ * Marcus Bointon's fixes but that I had not yet incorporated.
+ *
+ * Thanks to Daniel Schledermann (http://www.typoconsult.dk/) for
+ * suggesting a valuable fix with tag handling.
+ *
+ * Thanks to Wojciech Bajon (again!) for suggesting fixes and additions,
+ * including the tag handling that Daniel Schledermann pointed
+ * out but that I had not yet incorporated. I haven't (yet)
+ * incorporated all of Wojciech's changes, though I may at some
+ * future time.
+ *
+ * *** End of the housecleaning updates. Updated 08/08/07.
+ *
+ * @author Jon Abernathy
+ * @version 1.0.0
+ * @since PHP 4.0.2
+ */
+class html2text
+{
+
+ /**
+ * Contains the HTML content to convert.
+ *
+ * @var string $html
+ * @access public
+ */
+ var $html;
+
+ /**
+ * Contains the converted, formatted text.
+ *
+ * @var string $text
+ * @access public
+ */
+ var $text;
+
+ /**
+ * Maximum width of the formatted text, in columns.
+ *
+ * Set this value to 0 (or less) to ignore word wrapping
+ * and not constrain text to a fixed-width column.
+ *
+ * @var integer $width
+ * @access public
+ */
+ var $width = 70;
+
+ /**
+ * List of preg* regular expression patterns to search for,
+ * used in conjunction with $replace.
+ *
+ * @var array $search
+ * @access public
+ * @see $replace
+ */
+ var $search = array(
+ "/\r/", // Non-legal carriage return
+ "/[\n\t]+/", // Newlines and tabs
+ '/[ ]{2,}/', // Runs of spaces, pre-handling
+ '/ |