34 | We got requested to reset your password, if you do this then just click the following link to reset your password, if not just ignore this email,
35 |
36 | Click Following Link To Reset Your Password
37 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/mailer/PHPMailerAutoload.php:
--------------------------------------------------------------------------------
1 |
8 | * @author Jim Jagielski (jimjag)
9 | * @author Andy Prevost (codeworxtech)
10 | * @author Brent R. Matzelle (original founder)
11 | * @copyright 2012 - 2014 Marcus Bointon
12 | * @copyright 2010 - 2012 Jim Jagielski
13 | * @copyright 2004 - 2009 Andy Prevost
14 | * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
15 | * @note This program is distributed in the hope that it will be useful - WITHOUT
16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | * FITNESS FOR A PARTICULAR PURPOSE.
18 | */
19 |
20 | /**
21 | * PHPMailer SPL autoloader.
22 | * @param string $classname The name of the class to load
23 | */
24 | function PHPMailerAutoload($classname)
25 | {
26 | //Can't use __DIR__ as it's only in PHP 5.3+
27 | $filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php';
28 | if (is_readable($filename)) {
29 | require $filename;
30 | }
31 | }
32 |
33 | if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
34 | //SPL autoloading was introduced in PHP 5.1.2
35 | if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
36 | spl_autoload_register('PHPMailerAutoload', true, true);
37 | } else {
38 | spl_autoload_register('PHPMailerAutoload');
39 | }
40 | } else {
41 | /**
42 | * Fall back to traditional autoload for old PHP versions
43 | * @param string $classname The name of the class to load
44 | */
45 | function __autoload($classname)
46 | {
47 | PHPMailerAutoload($classname);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/mailer/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # PHPMailer - A full-featured email creation and transfer class for PHP
4 |
5 | Build status: [](https://travis-ci.org/PHPMailer/PHPMailer)
6 | [](https://scrutinizer-ci.com/g/PHPMailer/PHPMailer/)
7 | [](https://scrutinizer-ci.com/g/PHPMailer/PHPMailer/)
8 |
9 | [](https://packagist.org/packages/phpmailer/phpmailer) [](https://packagist.org/packages/phpmailer/phpmailer) [](https://packagist.org/packages/phpmailer/phpmailer) [](https://packagist.org/packages/phpmailer/phpmailer)
10 |
11 | ## Class Features
12 |
13 | - Probably the world's most popular code for sending email from PHP!
14 | - Used by many open-source projects: WordPress, Drupal, 1CRM, SugarCRM, Yii, Joomla! and many more
15 | - Integrated SMTP support - send without a local mail server
16 | - Send emails with multiple TOs, CCs, BCCs and REPLY-TOs
17 | - Multipart/alternative emails for mail clients that do not read HTML email
18 | - Support for UTF-8 content and 8bit, base64, binary, and quoted-printable encodings
19 | - SMTP authentication with LOGIN, PLAIN, NTLM, CRAM-MD5 and Google's XOAUTH2 mechanisms over SSL and TLS transports
20 | - Error messages in 47 languages!
21 | - DKIM and S/MIME signing support
22 | - Compatible with PHP 5.0 and later
23 | - Much more!
24 |
25 | ## Why you might need it
26 |
27 | 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.
28 |
29 | 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!
30 | *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.
31 |
32 | 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.
33 |
34 | ## License
35 |
36 | This software is distributed under the [LGPL 2.1](http://www.gnu.org/licenses/lgpl-2.1.html) license. Please read LICENSE for information on the
37 | software availability and distribution.
38 |
39 | ## Installation & loading
40 |
41 | PHPMailer is available via [Composer/Packagist](https://packagist.org/packages/phpmailer/phpmailer) (using semantic versioning), so just add this line to your `composer.json` file:
42 |
43 | ```json
44 | "phpmailer/phpmailer": "~5.2"
45 | ```
46 |
47 | or
48 |
49 | ```sh
50 | composer require phpmailer/phpmailer
51 | ```
52 |
53 | If you want to use the Gmail XOAUTH2 authentication class, you will also need to add a dependency on the `league/oauth2-client` package.
54 |
55 | Alternatively, copy the contents of the PHPMailer folder into one of the `include_path` directories specified in your PHP configuration. If you don't speak git or just want a tarball, click the 'zip' button at the top of the page in GitHub.
56 |
57 | If you're not using composer's autoloader, PHPMailer provides an SPL-compatible autoloader, and that is the preferred way of loading the library - just `require '/path/to/PHPMailerAutoload.php';` and everything should work. The autoloader does not throw errors if it can't find classes so it prepends itself to the SPL list, allowing your own (or your framework's) autoloader to catch errors. SPL autoloading was introduced in PHP 5.1.0, so if you are using a version older than that you will need to require/include each class manually.
58 |
59 | PHPMailer does *not* declare a namespace because namespaces were only introduced in PHP 5.3.
60 |
61 | If you want to use Google's XOAUTH2 authentication mechanism, you need to be running at least PHP 5.4, and load the dependencies listed in `composer.json`.
62 |
63 | ### Minimal installation
64 |
65 | While installing the entire package manually or with composer is simple, convenient and reliable, you may want to include only vital files in your project. At the very least you will need [class.phpmailer.php](https://github.com/PHPMailer/PHPMailer/tree/master/class.phpmailer.php). If you're using SMTP, you'll need [class.smtp.php](https://github.com/PHPMailer/PHPMailer/tree/master/class.smtp.php), and if you're using POP-before SMTP, you'll need [class.pop3.php](https://github.com/PHPMailer/PHPMailer/tree/master/class.pop3.php). For all of these, we recommend you use [the autoloader](https://github.com/PHPMailer/PHPMailer/tree/master/PHPMailerAutoload.php) too as otherwise you will either have to `require` all classes manually or use some other autoloader. You can skip the [language](https://github.com/PHPMailer/PHPMailer/tree/master/language/) folder if you're not showing errors to users and can make do with English-only errors. You may need the additional classes in the [extras](extras/) folder if you are using those features, including NTLM authentication and ics generation. If you're using Google XOAUTH2 you will need `class.phpmaileroauth.php` and `class.oauth.php` classes too, as well as the composer dependencies.
66 |
67 | ## A Simple Example
68 |
69 | ```php
70 | SMTPDebug = 3; // Enable verbose debug output
76 |
77 | $mail->isSMTP(); // Set mailer to use SMTP
78 | $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
79 | $mail->SMTPAuth = true; // Enable SMTP authentication
80 | $mail->Username = 'user@example.com'; // SMTP username
81 | $mail->Password = 'secret'; // SMTP password
82 | $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
83 | $mail->Port = 587; // TCP port to connect to
84 |
85 | $mail->setFrom('from@example.com', 'Mailer');
86 | $mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
87 | $mail->addAddress('ellen@example.com'); // Name is optional
88 | $mail->addReplyTo('info@example.com', 'Information');
89 | $mail->addCC('cc@example.com');
90 | $mail->addBCC('bcc@example.com');
91 |
92 | $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
93 | $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
94 | $mail->isHTML(true); // Set email format to HTML
95 |
96 | $mail->Subject = 'Here is the subject';
97 | $mail->Body = 'This is the HTML message body in bold!';
98 | $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
99 |
100 | if(!$mail->send()) {
101 | echo 'Message could not be sent.';
102 | echo 'Mailer Error: ' . $mail->ErrorInfo;
103 | } else {
104 | echo 'Message has been sent';
105 | }
106 | ```
107 |
108 | You'll find plenty more to play with in the [examples](https://github.com/PHPMailer/PHPMailer/tree/master/examples) folder.
109 |
110 | That's it. You should now be ready to use PHPMailer!
111 |
112 | ## Localization
113 | PHPMailer defaults to English, but in the [language](https://github.com/PHPMailer/PHPMailer/tree/master/language/) folder you'll find numerous (46 at the time of writing!) 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:
114 |
115 | ```php
116 | // To load the French version
117 | $mail->setLanguage('fr', '/optional/path/to/language/directory/');
118 | ```
119 |
120 | We welcome corrections and new languages - if you're looking for corrections to do, run the [phpmailerLangTest.php](https://github.com/PHPMailer/PHPMailer/tree/master/test/phpmailerLangTest.php) script in the tests folder and it will show any missing translations.
121 |
122 | ## Documentation
123 |
124 | Examples of how to use PHPMailer for common scenarios can be found in the [examples](https://github.com/PHPMailer/PHPMailer/tree/master/examples) folder. If you're looking for a good starting point, we recommend you start with [the Gmail example](https://github.com/PHPMailer/PHPMailer/tree/master/examples/gmail.phps).
125 |
126 | There are tips and a troubleshooting guide in the [GitHub wiki](https://github.com/PHPMailer/PHPMailer/wiki). If you're having trouble, this should be the first place you look as it's the most frequently updated.
127 |
128 | Complete generated API documentation is [available online](http://phpmailer.github.io/PHPMailer/).
129 |
130 | You'll find some basic user-level docs in the [docs](docs/) folder, and you can generate complete API-level documentation using the [generatedocs.sh](https://github.com/PHPMailer/PHPMailer/tree/master/docs/generatedocs.sh) shell script in the docs folder, though you'll need to install [PHPDocumentor](http://www.phpdoc.org) first. You may find [the unit tests](https://github.com/PHPMailer/PHPMailer/tree/master/test/phpmailerTest.php) a good source of how to do various operations such as encryption.
131 |
132 | If the documentation doesn't cover what you need, search the [many questions on Stack Overflow](http://stackoverflow.com/questions/tagged/phpmailer), and before you ask a question about "SMTP Error: Could not connect to SMTP host.", [read the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting).
133 |
134 | ## Tests
135 |
136 | There is a PHPUnit test script in the [test](https://github.com/PHPMailer/PHPMailer/tree/master/test/) folder.
137 |
138 | Build status: [](https://travis-ci.org/PHPMailer/PHPMailer)
139 |
140 | If this isn't passing, is there something you can do to help?
141 |
142 | ## Security
143 |
144 | Please disclose any vulnerabilities found responsibly - report any security problems found to the maintainers privately.
145 |
146 | PHPMailer versions prior to 5.2.14 (released November 2015) are vulnerable to [CVE-2015-8476](https://web.nvd.nist.gov/view/vuln/detail?vulnId=) an SMTP CRLF injection bug permitting arbitrary message sending.
147 |
148 | PHPMailer versions prior to 5.2.10 (released May 2015) are vulnerable to [CVE-2008-5619](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2008-5619), a remote code execution vulnerability in the bundled html2text library. This file was removed in 5.2.10, so if you are using a version prior to that and make use of the html2text function, it's vitally important that you upgrade and remove this file.
149 |
150 | See [SECURITY](https://github.com/PHPMailer/PHPMailer/tree/master/SECURITY) for older security issues.
151 |
152 | ## Contributing
153 |
154 | Please submit bug reports, suggestions and pull requests to the [GitHub issue tracker](https://github.com/PHPMailer/PHPMailer/issues).
155 |
156 | We're particularly interested in fixing edge-cases, expanding test coverage and updating translations.
157 |
158 | With the move to the PHPMailer GitHub organisation, you'll need to update any remote URLs referencing the old GitHub location with a command like this from within your clone:
159 |
160 | ```sh
161 | git remote set-url upstream https://github.com/PHPMailer/PHPMailer.git
162 | ```
163 |
164 | Please *don't* use the SourceForge or Google Code projects any more.
165 |
166 | ## Sponsorship
167 |
168 | Development time and resources for PHPMailer are provided by [Smartmessages.net](https://info.smartmessages.net/), a powerful email marketing system.
169 |
170 |
171 |
172 | Other contributions are gladly received, whether in beer 🍺, T-shirts 👕, Amazon wishlist raids, or cold, hard cash 💰.
173 |
174 | ## Changelog
175 |
176 | See [changelog](changelog.md).
177 |
178 | ## History
179 | - PHPMailer was originally written in 2001 by Brent R. Matzelle as a [SourceForge project](http://sourceforge.net/projects/phpmailer/).
180 | - Marcus Bointon (coolbru on SF) and Andy Prevost (codeworxtech) took over the project in 2004.
181 | - Became an Apache incubator project on Google Code in 2010, managed by Jim Jagielski.
182 | - Marcus created his fork on [GitHub](https://github.com/Synchro/PHPMailer).
183 | - Jim and Marcus decide to join forces and use GitHub as the canonical and official repo for PHPMailer.
184 | - PHPMailer moves to the [PHPMailer organisation](https://github.com/PHPMailer) on GitHub.
185 |
186 | ### What's changed since moving from SourceForge?
187 | - Official successor to the SourceForge and Google Code projects.
188 | - Test suite.
189 | - Continuous integration with Travis-CI.
190 | - Composer support.
191 | - Public development.
192 | - Additional languages and language strings.
193 | - CRAM-MD5 authentication support.
194 | - Preserves full repo history of authors, commits and branches from the original SourceForge project.
195 |
--------------------------------------------------------------------------------
/mailer/SECURITY:
--------------------------------------------------------------------------------
1 | # Security notices relating to PHPMailer
2 |
3 | Please disclose any vulnerabilities found responsibly - report any security problems found to the maintainers privately.
4 |
5 | PHPMailer versions prior to 5.2.14 (released November 2015) are vulnerable to [CVE-2015-8476](https://web.nvd.nist.gov/view/vuln/detail?vulnId=) an SMTP CRLF injection bug permitting arbitrary message sending.
6 |
7 | PHPMailer versions prior to 5.2.10 (released May 2015) are vulnerable to [CVE-2008-5619](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2008-5619), a remote code execution vulnerability in the bundled html2text library. This file was removed in 5.2.10, so if you are using a version prior to that and make use of the html2text function, it's vitally important that you upgrade and remove this file.
8 |
9 | PHPMailer versions prior to 2.0.7 and 2.2.1 are vulnerable to [CVE-2012-0796](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2012-0796), an email header injection attack.
10 |
11 | Joomla 1.6.0 uses PHPMailer in an unsafe way, allowing it to reveal local file paths, reported in [CVE-2011-3747](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2011-3747).
12 |
13 | PHPMailer didn't sanitise the `$lang_path` parameter in `SetLanguage`. This wasn't a problem in itself, but some apps (PHPClassifieds, ATutor) also failed to sanitise user-provided parameters passed to it, permitting semi-arbitrary local file inclusion, reported in [CVE-2010-4914](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2010-4914), [CVE-2007-2021](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2007-2021) and [CVE-2006-5734](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2006-5734).
14 |
15 | PHPMailer 1.7.2 and earlier contained a possible DDoS vulnerability reported in [CVE-2005-1807](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2005-1807).
16 |
17 | PHPMailer 1.7 and earlier (June 2003) have a possible vulnerability in the `SendmailSend` method where shell commands may not be sanitised. Reported in [CVE-2007-3215](https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2007-3215).
18 |
19 |
--------------------------------------------------------------------------------
/mailer/VERSION:
--------------------------------------------------------------------------------
1 | 5.2.16
--------------------------------------------------------------------------------
/mailer/class.phpmaileroauth.php:
--------------------------------------------------------------------------------
1 |
8 | * @author Jim Jagielski (jimjag)
9 | * @author Andy Prevost (codeworxtech)
10 | * @author Brent R. Matzelle (original founder)
11 | * @copyright 2012 - 2014 Marcus Bointon
12 | * @copyright 2010 - 2012 Jim Jagielski
13 | * @copyright 2004 - 2009 Andy Prevost
14 | * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
15 | * @note This program is distributed in the hope that it will be useful - WITHOUT
16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | * FITNESS FOR A PARTICULAR PURPOSE.
18 | */
19 |
20 | /**
21 | * PHPMailerOAuth - PHPMailer subclass adding OAuth support.
22 | * @package PHPMailer
23 | * @author @sherryl4george
24 | * @author Marcus Bointon (@Synchro)
25 | */
26 | class PHPMailerOAuth extends PHPMailer
27 | {
28 | /**
29 | * The OAuth user's email address
30 | * @var string
31 | */
32 | public $oauthUserEmail = '';
33 |
34 | /**
35 | * The OAuth refresh token
36 | * @var string
37 | */
38 | public $oauthRefreshToken = '';
39 |
40 | /**
41 | * The OAuth client ID
42 | * @var string
43 | */
44 | public $oauthClientId = '';
45 |
46 | /**
47 | * The OAuth client secret
48 | * @var string
49 | */
50 | public $oauthClientSecret = '';
51 |
52 | /**
53 | * An instance of the PHPMailerOAuthGoogle class.
54 | * @var PHPMailerOAuthGoogle
55 | * @access protected
56 | */
57 | protected $oauth = null;
58 |
59 | /**
60 | * Get a PHPMailerOAuthGoogle instance to use.
61 | * @return PHPMailerOAuthGoogle
62 | */
63 | public function getOAUTHInstance()
64 | {
65 | if (!is_object($this->oauth)) {
66 | $this->oauth = new PHPMailerOAuthGoogle(
67 | $this->oauthUserEmail,
68 | $this->oauthClientSecret,
69 | $this->oauthClientId,
70 | $this->oauthRefreshToken
71 | );
72 | }
73 | return $this->oauth;
74 | }
75 |
76 | /**
77 | * Initiate a connection to an SMTP server.
78 | * Overrides the original smtpConnect method to add support for OAuth.
79 | * @param array $options An array of options compatible with stream_context_create()
80 | * @uses SMTP
81 | * @access public
82 | * @return bool
83 | */
84 | public function smtpConnect($options = array())
85 | {
86 | if (is_null($this->smtp)) {
87 | $this->smtp = $this->getSMTPInstance();
88 | }
89 |
90 | if (is_null($this->oauth)) {
91 | $this->oauth = $this->getOAUTHInstance();
92 | }
93 |
94 | // Already connected?
95 | if ($this->smtp->connected()) {
96 | return true;
97 | }
98 |
99 | $this->smtp->setTimeout($this->Timeout);
100 | $this->smtp->setDebugLevel($this->SMTPDebug);
101 | $this->smtp->setDebugOutput($this->Debugoutput);
102 | $this->smtp->setVerp($this->do_verp);
103 | $hosts = explode(';', $this->Host);
104 | $lastexception = null;
105 |
106 | foreach ($hosts as $hostentry) {
107 | $hostinfo = array();
108 | if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
109 | // Not a valid host entry
110 | continue;
111 | }
112 | // $hostinfo[2]: optional ssl or tls prefix
113 | // $hostinfo[3]: the hostname
114 | // $hostinfo[4]: optional port number
115 | // The host string prefix can temporarily override the current setting for SMTPSecure
116 | // If it's not specified, the default value is used
117 | $prefix = '';
118 | $secure = $this->SMTPSecure;
119 | $tls = ($this->SMTPSecure == 'tls');
120 | if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) {
121 | $prefix = 'ssl://';
122 | $tls = false; // Can't have SSL and TLS at the same time
123 | $secure = 'ssl';
124 | } elseif ($hostinfo[2] == 'tls') {
125 | $tls = true;
126 | // tls doesn't use a prefix
127 | $secure = 'tls';
128 | }
129 | //Do we need the OpenSSL extension?
130 | $sslext = defined('OPENSSL_ALGO_SHA1');
131 | if ('tls' === $secure or 'ssl' === $secure) {
132 | //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
133 | if (!$sslext) {
134 | throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
135 | }
136 | }
137 | $host = $hostinfo[3];
138 | $port = $this->Port;
139 | $tport = (integer)$hostinfo[4];
140 | if ($tport > 0 and $tport < 65536) {
141 | $port = $tport;
142 | }
143 | if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
144 | try {
145 | if ($this->Helo) {
146 | $hello = $this->Helo;
147 | } else {
148 | $hello = $this->serverHostname();
149 | }
150 | $this->smtp->hello($hello);
151 | //Automatically enable TLS encryption if:
152 | // * it's not disabled
153 | // * we have openssl extension
154 | // * we are not already using SSL
155 | // * the server offers STARTTLS
156 | if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
157 | $tls = true;
158 | }
159 | if ($tls) {
160 | if (!$this->smtp->startTLS()) {
161 | throw new phpmailerException($this->lang('connect_host'));
162 | }
163 | // We must resend HELO after tls negotiation
164 | $this->smtp->hello($hello);
165 | }
166 | if ($this->SMTPAuth) {
167 | if (!$this->smtp->authenticate(
168 | $this->Username,
169 | $this->Password,
170 | $this->AuthType,
171 | $this->Realm,
172 | $this->Workstation,
173 | $this->oauth
174 | )
175 | ) {
176 | throw new phpmailerException($this->lang('authenticate'));
177 | }
178 | }
179 | return true;
180 | } catch (phpmailerException $exc) {
181 | $lastexception = $exc;
182 | $this->edebug($exc->getMessage());
183 | // We must have connected, but then failed TLS or Auth, so close connection nicely
184 | $this->smtp->quit();
185 | }
186 | }
187 | }
188 | // If we get here, all connection attempts have failed, so close connection hard
189 | $this->smtp->close();
190 | // As we've caught all exceptions, just report whatever the last one was
191 | if ($this->exceptions and !is_null($lastexception)) {
192 | throw $lastexception;
193 | }
194 | return false;
195 | }
196 | }
197 |
--------------------------------------------------------------------------------
/mailer/class.phpmaileroauthgoogle.php:
--------------------------------------------------------------------------------
1 |
8 | * @author Jim Jagielski (jimjag)
9 | * @author Andy Prevost (codeworxtech)
10 | * @author Brent R. Matzelle (original founder)
11 | * @copyright 2012 - 2014 Marcus Bointon
12 | * @copyright 2010 - 2012 Jim Jagielski
13 | * @copyright 2004 - 2009 Andy Prevost
14 | * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
15 | * @note This program is distributed in the hope that it will be useful - WITHOUT
16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | * FITNESS FOR A PARTICULAR PURPOSE.
18 | */
19 |
20 | /**
21 | * PHPMailerOAuthGoogle - Wrapper for League OAuth2 Google provider.
22 | * @package PHPMailer
23 | * @author @sherryl4george
24 | * @author Marcus Bointon (@Synchro)
25 | * @link https://github.com/thephpleague/oauth2-client
26 | */
27 | class PHPMailerOAuthGoogle
28 | {
29 | private $oauthUserEmail = '';
30 | private $oauthRefreshToken = '';
31 | private $oauthClientId = '';
32 | private $oauthClientSecret = '';
33 |
34 | /**
35 | * @param string $UserEmail
36 | * @param string $ClientSecret
37 | * @param string $ClientId
38 | * @param string $RefreshToken
39 | */
40 | public function __construct(
41 | $UserEmail,
42 | $ClientSecret,
43 | $ClientId,
44 | $RefreshToken
45 | ) {
46 | $this->oauthClientId = $ClientId;
47 | $this->oauthClientSecret = $ClientSecret;
48 | $this->oauthRefreshToken = $RefreshToken;
49 | $this->oauthUserEmail = $UserEmail;
50 | }
51 |
52 | private function getProvider()
53 | {
54 | return new League\OAuth2\Client\Provider\Google([
55 | 'clientId' => $this->oauthClientId,
56 | 'clientSecret' => $this->oauthClientSecret
57 | ]);
58 | }
59 |
60 | private function getGrant()
61 | {
62 | return new \League\OAuth2\Client\Grant\RefreshToken();
63 | }
64 |
65 | private function getToken()
66 | {
67 | $provider = $this->getProvider();
68 | $grant = $this->getGrant();
69 | return $provider->getAccessToken($grant, ['refresh_token' => $this->oauthRefreshToken]);
70 | }
71 |
72 | public function getOauth64()
73 | {
74 | $token = $this->getToken();
75 | return base64_encode("user=" . $this->oauthUserEmail . "\001auth=Bearer " . $token . "\001\001");
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/mailer/class.pop3.php:
--------------------------------------------------------------------------------
1 |
8 | * @author Jim Jagielski (jimjag)
9 | * @author Andy Prevost (codeworxtech)
10 | * @author Brent R. Matzelle (original founder)
11 | * @copyright 2012 - 2014 Marcus Bointon
12 | * @copyright 2010 - 2012 Jim Jagielski
13 | * @copyright 2004 - 2009 Andy Prevost
14 | * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
15 | * @note This program is distributed in the hope that it will be useful - WITHOUT
16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | * FITNESS FOR A PARTICULAR PURPOSE.
18 | */
19 |
20 | /**
21 | * PHPMailer POP-Before-SMTP Authentication Class.
22 | * Specifically for PHPMailer to use for RFC1939 POP-before-SMTP authentication.
23 | * Does not support APOP.
24 | * @package PHPMailer
25 | * @author Richard Davey (original author)
26 | * @author Marcus Bointon (Synchro/coolbru)
27 | * @author Jim Jagielski (jimjag)
28 | * @author Andy Prevost (codeworxtech)
29 | */
30 | class POP3
31 | {
32 | /**
33 | * The POP3 PHPMailer Version number.
34 | * @var string
35 | * @access public
36 | */
37 | public $Version = '5.2.16';
38 |
39 | /**
40 | * Default POP3 port number.
41 | * @var integer
42 | * @access public
43 | */
44 | public $POP3_PORT = 110;
45 |
46 | /**
47 | * Default timeout in seconds.
48 | * @var integer
49 | * @access public
50 | */
51 | public $POP3_TIMEOUT = 30;
52 |
53 | /**
54 | * POP3 Carriage Return + Line Feed.
55 | * @var string
56 | * @access public
57 | * @deprecated Use the constant instead
58 | */
59 | public $CRLF = "\r\n";
60 |
61 | /**
62 | * Debug display level.
63 | * Options: 0 = no, 1+ = yes
64 | * @var integer
65 | * @access public
66 | */
67 | public $do_debug = 0;
68 |
69 | /**
70 | * POP3 mail server hostname.
71 | * @var string
72 | * @access public
73 | */
74 | public $host;
75 |
76 | /**
77 | * POP3 port number.
78 | * @var integer
79 | * @access public
80 | */
81 | public $port;
82 |
83 | /**
84 | * POP3 Timeout Value in seconds.
85 | * @var integer
86 | * @access public
87 | */
88 | public $tval;
89 |
90 | /**
91 | * POP3 username
92 | * @var string
93 | * @access public
94 | */
95 | public $username;
96 |
97 | /**
98 | * POP3 password.
99 | * @var string
100 | * @access public
101 | */
102 | public $password;
103 |
104 | /**
105 | * Resource handle for the POP3 connection socket.
106 | * @var resource
107 | * @access protected
108 | */
109 | protected $pop_conn;
110 |
111 | /**
112 | * Are we connected?
113 | * @var boolean
114 | * @access protected
115 | */
116 | protected $connected = false;
117 |
118 | /**
119 | * Error container.
120 | * @var array
121 | * @access protected
122 | */
123 | protected $errors = array();
124 |
125 | /**
126 | * Line break constant
127 | */
128 | const CRLF = "\r\n";
129 |
130 | /**
131 | * Simple static wrapper for all-in-one POP before SMTP
132 | * @param $host
133 | * @param integer|boolean $port The port number to connect to
134 | * @param integer|boolean $timeout The timeout value
135 | * @param string $username
136 | * @param string $password
137 | * @param integer $debug_level
138 | * @return boolean
139 | */
140 | public static function popBeforeSmtp(
141 | $host,
142 | $port = false,
143 | $timeout = false,
144 | $username = '',
145 | $password = '',
146 | $debug_level = 0
147 | ) {
148 | $pop = new POP3;
149 | return $pop->authorise($host, $port, $timeout, $username, $password, $debug_level);
150 | }
151 |
152 | /**
153 | * Authenticate with a POP3 server.
154 | * A connect, login, disconnect sequence
155 | * appropriate for POP-before SMTP authorisation.
156 | * @access public
157 | * @param string $host The hostname to connect to
158 | * @param integer|boolean $port The port number to connect to
159 | * @param integer|boolean $timeout The timeout value
160 | * @param string $username
161 | * @param string $password
162 | * @param integer $debug_level
163 | * @return boolean
164 | */
165 | public function authorise($host, $port = false, $timeout = false, $username = '', $password = '', $debug_level = 0)
166 | {
167 | $this->host = $host;
168 | // If no port value provided, use default
169 | if (false === $port) {
170 | $this->port = $this->POP3_PORT;
171 | } else {
172 | $this->port = (integer)$port;
173 | }
174 | // If no timeout value provided, use default
175 | if (false === $timeout) {
176 | $this->tval = $this->POP3_TIMEOUT;
177 | } else {
178 | $this->tval = (integer)$timeout;
179 | }
180 | $this->do_debug = $debug_level;
181 | $this->username = $username;
182 | $this->password = $password;
183 | // Reset the error log
184 | $this->errors = array();
185 | // connect
186 | $result = $this->connect($this->host, $this->port, $this->tval);
187 | if ($result) {
188 | $login_result = $this->login($this->username, $this->password);
189 | if ($login_result) {
190 | $this->disconnect();
191 | return true;
192 | }
193 | }
194 | // We need to disconnect regardless of whether the login succeeded
195 | $this->disconnect();
196 | return false;
197 | }
198 |
199 | /**
200 | * Connect to a POP3 server.
201 | * @access public
202 | * @param string $host
203 | * @param integer|boolean $port
204 | * @param integer $tval
205 | * @return boolean
206 | */
207 | public function connect($host, $port = false, $tval = 30)
208 | {
209 | // Are we already connected?
210 | if ($this->connected) {
211 | return true;
212 | }
213 |
214 | //On Windows this will raise a PHP Warning error if the hostname doesn't exist.
215 | //Rather than suppress it with @fsockopen, capture it cleanly instead
216 | set_error_handler(array($this, 'catchWarning'));
217 |
218 | if (false === $port) {
219 | $port = $this->POP3_PORT;
220 | }
221 |
222 | // connect to the POP3 server
223 | $this->pop_conn = fsockopen(
224 | $host, // POP3 Host
225 | $port, // Port #
226 | $errno, // Error Number
227 | $errstr, // Error Message
228 | $tval
229 | ); // Timeout (seconds)
230 | // Restore the error handler
231 | restore_error_handler();
232 |
233 | // Did we connect?
234 | if (false === $this->pop_conn) {
235 | // It would appear not...
236 | $this->setError(array(
237 | 'error' => "Failed to connect to server $host on port $port",
238 | 'errno' => $errno,
239 | 'errstr' => $errstr
240 | ));
241 | return false;
242 | }
243 |
244 | // Increase the stream time-out
245 | stream_set_timeout($this->pop_conn, $tval, 0);
246 |
247 | // Get the POP3 server response
248 | $pop3_response = $this->getResponse();
249 | // Check for the +OK
250 | if ($this->checkResponse($pop3_response)) {
251 | // The connection is established and the POP3 server is talking
252 | $this->connected = true;
253 | return true;
254 | }
255 | return false;
256 | }
257 |
258 | /**
259 | * Log in to the POP3 server.
260 | * Does not support APOP (RFC 2828, 4949).
261 | * @access public
262 | * @param string $username
263 | * @param string $password
264 | * @return boolean
265 | */
266 | public function login($username = '', $password = '')
267 | {
268 | if (!$this->connected) {
269 | $this->setError('Not connected to POP3 server');
270 | }
271 | if (empty($username)) {
272 | $username = $this->username;
273 | }
274 | if (empty($password)) {
275 | $password = $this->password;
276 | }
277 |
278 | // Send the Username
279 | $this->sendString("USER $username" . self::CRLF);
280 | $pop3_response = $this->getResponse();
281 | if ($this->checkResponse($pop3_response)) {
282 | // Send the Password
283 | $this->sendString("PASS $password" . self::CRLF);
284 | $pop3_response = $this->getResponse();
285 | if ($this->checkResponse($pop3_response)) {
286 | return true;
287 | }
288 | }
289 | return false;
290 | }
291 |
292 | /**
293 | * Disconnect from the POP3 server.
294 | * @access public
295 | */
296 | public function disconnect()
297 | {
298 | $this->sendString('QUIT');
299 | //The QUIT command may cause the daemon to exit, which will kill our connection
300 | //So ignore errors here
301 | try {
302 | @fclose($this->pop_conn);
303 | } catch (Exception $e) {
304 | //Do nothing
305 | };
306 | }
307 |
308 | /**
309 | * Get a response from the POP3 server.
310 | * $size is the maximum number of bytes to retrieve
311 | * @param integer $size
312 | * @return string
313 | * @access protected
314 | */
315 | protected function getResponse($size = 128)
316 | {
317 | $response = fgets($this->pop_conn, $size);
318 | if ($this->do_debug >= 1) {
319 | echo "Server -> Client: $response";
320 | }
321 | return $response;
322 | }
323 |
324 | /**
325 | * Send raw data to the POP3 server.
326 | * @param string $string
327 | * @return integer
328 | * @access protected
329 | */
330 | protected function sendString($string)
331 | {
332 | if ($this->pop_conn) {
333 | if ($this->do_debug >= 2) { //Show client messages when debug >= 2
334 | echo "Client -> Server: $string";
335 | }
336 | return fwrite($this->pop_conn, $string, strlen($string));
337 | }
338 | return 0;
339 | }
340 |
341 | /**
342 | * Checks the POP3 server response.
343 | * Looks for for +OK or -ERR.
344 | * @param string $string
345 | * @return boolean
346 | * @access protected
347 | */
348 | protected function checkResponse($string)
349 | {
350 | if (substr($string, 0, 3) !== '+OK') {
351 | $this->setError(array(
352 | 'error' => "Server reported an error: $string",
353 | 'errno' => 0,
354 | 'errstr' => ''
355 | ));
356 | return false;
357 | } else {
358 | return true;
359 | }
360 | }
361 |
362 | /**
363 | * Add an error to the internal error store.
364 | * Also display debug output if it's enabled.
365 | * @param $error
366 | * @access protected
367 | */
368 | protected function setError($error)
369 | {
370 | $this->errors[] = $error;
371 | if ($this->do_debug >= 1) {
372 | echo '