mirror of
https://github.com/PHPMailer/PHPMailer.git
synced 2024-09-19 17:42:14 +02:00
Consistent comment style
This commit is contained in:
parent
e28e3552a5
commit
0f24617b0c
40
README.md
40
README.md
@ -80,43 +80,43 @@ While installing the entire package manually or with Composer is simple, conveni
|
||||
|
||||
```php
|
||||
<?php
|
||||
// Import PHPMailer classes into the global namespace
|
||||
// These must be at the top of your script, not inside a function
|
||||
//Import PHPMailer classes into the global namespace
|
||||
//These must be at the top of your script, not inside a function
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
// Load Composer's autoloader
|
||||
//Load Composer's autoloader
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
// Instantiation and passing `true` enables exceptions
|
||||
//Instantiation and passing `true` enables exceptions
|
||||
$mail = new PHPMailer(true);
|
||||
|
||||
try {
|
||||
//Server settings
|
||||
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
|
||||
$mail->isSMTP(); // Send using SMTP
|
||||
$mail->Host = 'smtp.example.com'; // Set the SMTP server to send through
|
||||
$mail->SMTPAuth = true; // Enable SMTP authentication
|
||||
$mail->Username = 'user@example.com'; // SMTP username
|
||||
$mail->Password = 'secret'; // SMTP password
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
|
||||
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
|
||||
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
|
||||
$mail->isSMTP(); //Send using SMTP
|
||||
$mail->Host = 'smtp.example.com'; //Set the SMTP server to send through
|
||||
$mail->SMTPAuth = true; //Enable SMTP authentication
|
||||
$mail->Username = 'user@example.com'; //SMTP username
|
||||
$mail->Password = 'secret'; //SMTP password
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
|
||||
$mail->Port = 587; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
|
||||
|
||||
//Recipients
|
||||
$mail->setFrom('from@example.com', 'Mailer');
|
||||
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
|
||||
$mail->addAddress('ellen@example.com'); // Name is optional
|
||||
$mail->addAddress('joe@example.net', 'Joe User'); //Add a recipient
|
||||
$mail->addAddress('ellen@example.com'); //Name is optional
|
||||
$mail->addReplyTo('info@example.com', 'Information');
|
||||
$mail->addCC('cc@example.com');
|
||||
$mail->addBCC('bcc@example.com');
|
||||
|
||||
// Attachments
|
||||
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
|
||||
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
|
||||
//Attachments
|
||||
$mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
|
||||
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
|
||||
|
||||
// Content
|
||||
$mail->isHTML(true); // Set email format to HTML
|
||||
//Content
|
||||
$mail->isHTML(true); //Set email format to HTML
|
||||
$mail->Subject = 'Here is the subject';
|
||||
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
|
||||
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
|
||||
@ -138,7 +138,7 @@ That's it. You should now be ready to use PHPMailer!
|
||||
PHPMailer defaults to English, but in the [language](https://github.com/PHPMailer/PHPMailer/tree/master/language/) folder you'll find many 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 French version
|
||||
//To load the French version
|
||||
$mail->setLanguage('fr', '/optional/path/to/language/directory/');
|
||||
```
|
||||
|
||||
|
@ -52,9 +52,9 @@ try {
|
||||
$mail->addCC('john@example.com', 'John Doe');
|
||||
$mail->Subject = 'PHPMailer Test Subject';
|
||||
$mail->msgHTML(file_get_contents('../examples/contents.html'));
|
||||
// optional - msgHTML will create an alternate automatically
|
||||
//Optional - msgHTML will create an alternate automatically
|
||||
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
|
||||
$mail->addAttachment('images/phpmailer_mini.png'); // attachment
|
||||
$mail->addAttachment('images/phpmailer_mini.png');
|
||||
$mail->action_function = 'callbackAction';
|
||||
$mail->send();
|
||||
} catch (Exception $e) {
|
||||
|
@ -61,11 +61,11 @@ class MyPHPMailer extends PHPMailer
|
||||
try {
|
||||
//Instantiate your new class, making use of the new `$body` parameter
|
||||
$mail = new myPHPMailer(true, '<strong>This is the message body</strong>');
|
||||
// Now you only need to set things that are different from the defaults you defined
|
||||
//Now you only need to set things that are different from the defaults you defined
|
||||
$mail->addAddress('jane@example.com', 'Jane User');
|
||||
$mail->Subject = 'Here is the subject';
|
||||
$mail->addAttachment(__FILE__, 'myPHPMailer.php');
|
||||
$mail->send(); //no need to check for errors - the exception handler will do it
|
||||
$mail->send(); //No need to check for errors - the exception handler will do it
|
||||
} catch (Exception $e) {
|
||||
//Note that this is catching the PHPMailer Exception class, not the global \Exception type!
|
||||
echo 'Caught a ' . get_class($e) . ': ' . $e->getMessage();
|
||||
|
@ -20,16 +20,16 @@ $mail = new PHPMailer();
|
||||
$mail->isSMTP();
|
||||
|
||||
//Enable SMTP debugging
|
||||
// SMTP::DEBUG_OFF = off (for production use)
|
||||
// SMTP::DEBUG_CLIENT = client messages
|
||||
// SMTP::DEBUG_SERVER = client and server messages
|
||||
//SMTP::DEBUG_OFF = off (for production use)
|
||||
//SMTP::DEBUG_CLIENT = client messages
|
||||
//SMTP::DEBUG_SERVER = client and server messages
|
||||
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
|
||||
|
||||
//Set the hostname of the mail server
|
||||
$mail->Host = 'smtp.gmail.com';
|
||||
// use
|
||||
// $mail->Host = gethostbyname('smtp.gmail.com');
|
||||
// if your network does not support SMTP over IPv6
|
||||
//Use `$mail->Host = gethostbyname('smtp.gmail.com');`
|
||||
//if your network does not support SMTP over IPv6,
|
||||
//though this may cause issues with TLS
|
||||
|
||||
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
|
||||
$mail->Port = 587;
|
||||
|
@ -8,7 +8,7 @@
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\OAuth;
|
||||
// Alias the League Google OAuth2 provider class
|
||||
//Alias the League Google OAuth2 provider class
|
||||
use League\OAuth2\Client\Provider\Google;
|
||||
|
||||
//SMTP needs accurate times, and the PHP time zone MUST be set
|
||||
@ -26,9 +26,9 @@ $mail = new PHPMailer();
|
||||
$mail->isSMTP();
|
||||
|
||||
//Enable SMTP debugging
|
||||
// SMTP::DEBUG_OFF = off (for production use)
|
||||
// SMTP::DEBUG_CLIENT = client messages
|
||||
// SMTP::DEBUG_SERVER = client and server messages
|
||||
//SMTP::DEBUG_OFF = off (for production use)
|
||||
//SMTP::DEBUG_CLIENT = client messages
|
||||
//SMTP::DEBUG_SERVER = client and server messages
|
||||
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
|
||||
|
||||
//Set the hostname of the mail server
|
||||
|
@ -22,7 +22,7 @@ $body = file_get_contents('contents.html');
|
||||
$mail->isSMTP();
|
||||
$mail->Host = 'smtp.example.com';
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->SMTPKeepAlive = true; // SMTP connection will not close after each email sent, reduces SMTP overhead
|
||||
$mail->SMTPKeepAlive = true; //SMTP connection will not close after each email sent, reduces SMTP overhead
|
||||
$mail->Port = 25;
|
||||
$mail->Username = 'yourname@example.com';
|
||||
$mail->Password = 'yourpassword';
|
||||
|
@ -24,9 +24,9 @@ $mail = new PHPMailer(true);
|
||||
try {
|
||||
$mail->isSMTP();
|
||||
//Enable SMTP debugging
|
||||
// SMTP::DEBUG_OFF = off (for production use)
|
||||
// SMTP::DEBUG_CLIENT = client messages
|
||||
// SMTP::DEBUG_SERVER = client and server messages
|
||||
//SMTP::DEBUG_OFF = off (for production use)
|
||||
//SMTP::DEBUG_CLIENT = client messages
|
||||
//SMTP::DEBUG_SERVER = client and server messages
|
||||
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
|
||||
//Set the hostname of the mail server
|
||||
$mail->Host = 'mail.example.com';
|
||||
|
@ -11,23 +11,23 @@ require '../vendor/autoload.php';
|
||||
|
||||
$msg = '';
|
||||
if (array_key_exists('userfile', $_FILES)) {
|
||||
// First handle the upload
|
||||
// Don't trust provided filename - same goes for MIME types
|
||||
// See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
|
||||
// Extract an extension from the provided filename
|
||||
//First handle the upload
|
||||
//Don't trust provided filename - same goes for MIME types
|
||||
//See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
|
||||
//Extract an extension from the provided filename
|
||||
$ext = PHPMailer::mb_pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION);
|
||||
// Define a safe location to move the uploaded file to, preserving the extension
|
||||
//Define a safe location to move the uploaded file to, preserving the extension
|
||||
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'])) . '.' . $ext;
|
||||
|
||||
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
|
||||
// Upload handled successfully
|
||||
// Now create a message
|
||||
//Upload handled successfully
|
||||
//Now create a message
|
||||
$mail = new PHPMailer();
|
||||
$mail->setFrom('from@example.com', 'First Last');
|
||||
$mail->addAddress('whoto@example.com', 'John Doe');
|
||||
$mail->Subject = 'PHPMailer file sender';
|
||||
$mail->Body = 'My message body';
|
||||
// Attach the uploaded file
|
||||
//Attach the uploaded file
|
||||
if (!$mail->addAttachment($uploadfile, 'My uploaded file')) {
|
||||
$msg .= 'Failed to attach file ' . $_FILES['userfile']['name'];
|
||||
}
|
||||
|
@ -11,17 +11,17 @@ require '../vendor/autoload.php';
|
||||
|
||||
$msg = '';
|
||||
if (array_key_exists('userfile', $_FILES)) {
|
||||
// Create a message
|
||||
//Create a message
|
||||
$mail = new PHPMailer();
|
||||
$mail->setFrom('from@example.com', 'First Last');
|
||||
$mail->addAddress('whoto@example.com', 'John Doe');
|
||||
$mail->Subject = 'PHPMailer file sender';
|
||||
$mail->Body = 'My message body';
|
||||
// Attach multiple files one by one
|
||||
//Attach multiple files one by one
|
||||
for ($ct = 0, $ctMax = count($_FILES['userfile']['tmp_name']); $ct < $ctMax; $ct++) {
|
||||
// Extract an extension from the provided filename
|
||||
//Extract an extension from the provided filename
|
||||
$ext = PHPMailer::mb_pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION);
|
||||
// Define a safe location to move the uploaded file to, preserving the extension
|
||||
//Define a safe location to move the uploaded file to, preserving the extension
|
||||
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'][$ct])) . '.' . $ext;
|
||||
$filename = $_FILES['userfile']['name'][$ct];
|
||||
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$ct], $uploadfile)) {
|
||||
|
@ -11,7 +11,7 @@ require '../vendor/autoload.php';
|
||||
|
||||
//Create a new PHPMailer instance
|
||||
$mail = new PHPMailer();
|
||||
// Set PHPMailer to use the sendmail transport
|
||||
//Set PHPMailer to use the sendmail transport
|
||||
$mail->isSendmail();
|
||||
//Set who the message is to be sent from
|
||||
$mail->setFrom('from@example.com', 'First Last');
|
||||
|
@ -19,9 +19,9 @@ $mail = new PHPMailer();
|
||||
//Tell PHPMailer to use SMTP
|
||||
$mail->isSMTP();
|
||||
//Enable SMTP debugging
|
||||
// SMTP::DEBUG_OFF = off (for production use)
|
||||
// SMTP::DEBUG_CLIENT = client messages
|
||||
// SMTP::DEBUG_SERVER = client and server messages
|
||||
//SMTP::DEBUG_OFF = off (for production use)
|
||||
//SMTP::DEBUG_CLIENT = client messages
|
||||
//SMTP::DEBUG_SERVER = client and server messages
|
||||
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
|
||||
//Set the hostname of the mail server
|
||||
$mail->Host = 'mail.example.com';
|
||||
|
@ -35,7 +35,7 @@ class SMTPLowMemory extends SMTP
|
||||
* NOTE: this does not count towards line-length limit.
|
||||
*/
|
||||
|
||||
// Normalize line breaks
|
||||
//Normalize line breaks
|
||||
$msg_data = str_replace(["\r\n", "\r"], "\n", $msg_data);
|
||||
|
||||
/* To distinguish between a complete RFC822 message and a plain message body, we check if the first field
|
||||
|
@ -19,9 +19,9 @@ $mail = new PHPMailer();
|
||||
//Tell PHPMailer to use SMTP
|
||||
$mail->isSMTP();
|
||||
//Enable SMTP debugging
|
||||
// SMTP::DEBUG_OFF = off (for production use)
|
||||
// SMTP::DEBUG_CLIENT = client messages
|
||||
// SMTP::DEBUG_SERVER = client and server messages
|
||||
//SMTP::DEBUG_OFF = off (for production use)
|
||||
//SMTP::DEBUG_CLIENT = client messages
|
||||
//SMTP::DEBUG_SERVER = client and server messages
|
||||
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
|
||||
//Set the hostname of the mail server
|
||||
$mail->Host = 'mail.example.com';
|
||||
|
@ -21,9 +21,9 @@ $mail = new PHPMailer();
|
||||
$mail->isSMTP();
|
||||
|
||||
//Enable SMTP debugging
|
||||
// SMTP::DEBUG_OFF = off (for production use)
|
||||
// SMTP::DEBUG_CLIENT = client messages
|
||||
// SMTP::DEBUG_SERVER = client and server messages
|
||||
//SMTP::DEBUG_OFF = off (for production use)
|
||||
//SMTP::DEBUG_CLIENT = client messages
|
||||
//SMTP::DEBUG_SERVER = client and server messages
|
||||
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
|
||||
|
||||
//Set the hostname of the mail server
|
||||
|
@ -38,11 +38,11 @@ namespace PHPMailer\PHPMailer;
|
||||
* Plenty to choose from here:
|
||||
* @see http://oauth2-client.thephpleague.com/providers/thirdparty/
|
||||
*/
|
||||
// @see https://github.com/thephpleague/oauth2-google
|
||||
//@see https://github.com/thephpleague/oauth2-google
|
||||
use League\OAuth2\Client\Provider\Google;
|
||||
// @see https://packagist.org/packages/hayageek/oauth2-yahoo
|
||||
//@see https://packagist.org/packages/hayageek/oauth2-yahoo
|
||||
use Hayageek\OAuth2\Client\Provider\Yahoo;
|
||||
// @see https://github.com/stevenmaguire/oauth2-microsoft
|
||||
//@see https://github.com/stevenmaguire/oauth2-microsoft
|
||||
use Stevenmaguire\OAuth2\Client\Provider\Microsoft;
|
||||
|
||||
if (!isset($_GET['code']) && !isset($_GET['provider'])) {
|
||||
@ -121,26 +121,26 @@ if (null === $provider) {
|
||||
}
|
||||
|
||||
if (!isset($_GET['code'])) {
|
||||
// If we don't have an authorization code then get one
|
||||
//If we don't have an authorization code then get one
|
||||
$authUrl = $provider->getAuthorizationUrl($options);
|
||||
$_SESSION['oauth2state'] = $provider->getState();
|
||||
header('Location: ' . $authUrl);
|
||||
exit;
|
||||
// Check given state against previously stored one to mitigate CSRF attack
|
||||
//Check given state against previously stored one to mitigate CSRF attack
|
||||
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
|
||||
unset($_SESSION['oauth2state']);
|
||||
unset($_SESSION['provider']);
|
||||
exit('Invalid state');
|
||||
} else {
|
||||
unset($_SESSION['provider']);
|
||||
// Try to get an access token (using the authorization code grant)
|
||||
//Try to get an access token (using the authorization code grant)
|
||||
$token = $provider->getAccessToken(
|
||||
'authorization_code',
|
||||
[
|
||||
'code' => $_GET['code']
|
||||
]
|
||||
);
|
||||
// Use this to interact with an API on the users behalf
|
||||
// Use this to get a new access token if the old one expires
|
||||
//Use this to interact with an API on the users behalf
|
||||
//Use this to get a new access token if the old one expires
|
||||
echo 'Refresh Token: ', $token->getRefreshToken();
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ class OAuth
|
||||
*/
|
||||
public function getOauth64()
|
||||
{
|
||||
// Get a new token if it's not available or has expired
|
||||
//Get a new token if it's not available or has expired
|
||||
if (null === $this->oauthToken || $this->oauthToken->hasExpired()) {
|
||||
$this->oauthToken = $this->getToken();
|
||||
}
|
||||
|
@ -1075,7 +1075,7 @@ class PHPMailer
|
||||
$name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
|
||||
$pos = strrpos($address, '@');
|
||||
if (false === $pos) {
|
||||
// At-sign is missing.
|
||||
//At-sign is missing.
|
||||
$error_message = sprintf(
|
||||
'%s (%s): %s',
|
||||
$this->lang('invalid_address'),
|
||||
@ -1091,7 +1091,7 @@ class PHPMailer
|
||||
return false;
|
||||
}
|
||||
$params = [$kind, $address, $name];
|
||||
// Enqueue addresses with IDN until we know the PHPMailer::$CharSet.
|
||||
//Enqueue addresses with IDN until we know the PHPMailer::$CharSet.
|
||||
if (static::idnSupported() && $this->has8bitChars(substr($address, ++$pos))) {
|
||||
if ('Reply-To' !== $kind) {
|
||||
if (!array_key_exists($address, $this->RecipientsQueue)) {
|
||||
@ -1108,7 +1108,7 @@ class PHPMailer
|
||||
return false;
|
||||
}
|
||||
|
||||
// Immediately add standard addresses without IDN.
|
||||
//Immediately add standard addresses without IDN.
|
||||
return call_user_func_array([$this, 'addAnAddress'], $params);
|
||||
}
|
||||
|
||||
@ -1258,7 +1258,7 @@ class PHPMailer
|
||||
{
|
||||
$address = trim($address);
|
||||
$name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
|
||||
// Don't validate now addresses with IDN. Will be done in send().
|
||||
//Don't validate now addresses with IDN. Will be done in send().
|
||||
$pos = strrpos($address, '@');
|
||||
if (
|
||||
(false === $pos)
|
||||
@ -1411,7 +1411,7 @@ class PHPMailer
|
||||
*/
|
||||
public function punyencodeAddress($address)
|
||||
{
|
||||
// Verify we have required functions, CharSet, and at-sign.
|
||||
//Verify we have required functions, CharSet, and at-sign.
|
||||
$pos = strrpos($address, '@');
|
||||
if (
|
||||
!empty($this->CharSet) &&
|
||||
@ -1419,7 +1419,7 @@ class PHPMailer
|
||||
static::idnSupported()
|
||||
) {
|
||||
$domain = substr($address, ++$pos);
|
||||
// Verify CharSet string is a valid one, and domain properly encoded in this CharSet.
|
||||
//Verify CharSet string is a valid one, and domain properly encoded in this CharSet.
|
||||
if ($this->has8bitChars($domain) && @mb_check_encoding($domain, $this->CharSet)) {
|
||||
//Convert the domain from whatever charset it's in to UTF-8
|
||||
$domain = mb_convert_encoding($domain, self::CHARSET_UTF8, $this->CharSet);
|
||||
@ -1508,10 +1508,10 @@ class PHPMailer
|
||||
}
|
||||
|
||||
try {
|
||||
$this->error_count = 0; // Reset errors
|
||||
$this->error_count = 0; //Reset errors
|
||||
$this->mailHeader = '';
|
||||
|
||||
// Dequeue recipient and Reply-To addresses with IDN
|
||||
//Dequeue recipient and Reply-To addresses with IDN
|
||||
foreach (array_merge($this->RecipientsQueue, $this->ReplyToQueue) as $params) {
|
||||
$params[1] = $this->punyencodeAddress($params[1]);
|
||||
call_user_func_array([$this, 'addAnAddress'], $params);
|
||||
@ -1520,7 +1520,7 @@ class PHPMailer
|
||||
throw new Exception($this->lang('provide_address'), self::STOP_CRITICAL);
|
||||
}
|
||||
|
||||
// Validate From, Sender, and ConfirmReadingTo addresses
|
||||
//Validate From, Sender, and ConfirmReadingTo addresses
|
||||
foreach (['From', 'Sender', 'ConfirmReadingTo'] as $address_kind) {
|
||||
$this->$address_kind = trim($this->$address_kind);
|
||||
if (empty($this->$address_kind)) {
|
||||
@ -1544,29 +1544,29 @@ class PHPMailer
|
||||
}
|
||||
}
|
||||
|
||||
// Set whether the message is multipart/alternative
|
||||
//Set whether the message is multipart/alternative
|
||||
if ($this->alternativeExists()) {
|
||||
$this->ContentType = static::CONTENT_TYPE_MULTIPART_ALTERNATIVE;
|
||||
}
|
||||
|
||||
$this->setMessageType();
|
||||
// Refuse to send an empty message unless we are specifically allowing it
|
||||
//Refuse to send an empty message unless we are specifically allowing it
|
||||
if (!$this->AllowEmpty && empty($this->Body)) {
|
||||
throw new Exception($this->lang('empty_message'), self::STOP_CRITICAL);
|
||||
}
|
||||
|
||||
//Trim subject consistently
|
||||
$this->Subject = trim($this->Subject);
|
||||
// Create body before headers in case body makes changes to headers (e.g. altering transfer encoding)
|
||||
//Create body before headers in case body makes changes to headers (e.g. altering transfer encoding)
|
||||
$this->MIMEHeader = '';
|
||||
$this->MIMEBody = $this->createBody();
|
||||
// createBody may have added some headers, so retain them
|
||||
//createBody may have added some headers, so retain them
|
||||
$tempheaders = $this->MIMEHeader;
|
||||
$this->MIMEHeader = $this->createHeader();
|
||||
$this->MIMEHeader .= $tempheaders;
|
||||
|
||||
// To capture the complete message when using mail(), create
|
||||
// an extra header list which createHeader() doesn't fold in
|
||||
//To capture the complete message when using mail(), create
|
||||
//an extra header list which createHeader() doesn't fold in
|
||||
if ('mail' === $this->Mailer) {
|
||||
if (count($this->to) > 0) {
|
||||
$this->mailHeader .= $this->addrAppend('To', $this->to);
|
||||
@ -1579,7 +1579,7 @@ class PHPMailer
|
||||
);
|
||||
}
|
||||
|
||||
// Sign with DKIM if enabled
|
||||
//Sign with DKIM if enabled
|
||||
if (
|
||||
!empty($this->DKIM_domain)
|
||||
&& !empty($this->DKIM_selector)
|
||||
@ -1620,7 +1620,7 @@ class PHPMailer
|
||||
public function postSend()
|
||||
{
|
||||
try {
|
||||
// Choose the mailer and send through it
|
||||
//Choose the mailer and send through it
|
||||
switch ($this->Mailer) {
|
||||
case 'sendmail':
|
||||
case 'qmail':
|
||||
@ -1745,7 +1745,7 @@ class PHPMailer
|
||||
*/
|
||||
protected static function isShellSafe($string)
|
||||
{
|
||||
// Future-proof
|
||||
//Future-proof
|
||||
if (
|
||||
escapeshellcmd($string) !== $string
|
||||
|| !in_array(escapeshellarg($string), ["'$string'", "\"$string\""])
|
||||
@ -1758,9 +1758,9 @@ class PHPMailer
|
||||
for ($i = 0; $i < $length; ++$i) {
|
||||
$c = $string[$i];
|
||||
|
||||
// All other characters have a special meaning in at least one common shell, including = and +.
|
||||
// Full stop (.) has a special meaning in cmd.exe, but its impact should be negligible here.
|
||||
// Note that this does permit non-Latin alphanumeric characters based on the current locale.
|
||||
//All other characters have a special meaning in at least one common shell, including = and +.
|
||||
//Full stop (.) has a special meaning in cmd.exe, but its impact should be negligible here.
|
||||
//Note that this does permit non-Latin alphanumeric characters based on the current locale.
|
||||
if (!ctype_alnum($c) && strpos('@_-.', $c) === false) {
|
||||
return false;
|
||||
}
|
||||
@ -1830,7 +1830,7 @@ class PHPMailer
|
||||
//Sendmail docs: http://www.sendmail.org/~ca/email/man/sendmail.html
|
||||
//Qmail docs: http://www.qmail.org/man/man8/qmail-inject.html
|
||||
//Example problem: https://www.drupal.org/node/1057954
|
||||
// CVE-2016-10033, CVE-2016-10045: Don't pass -f if characters will be escaped.
|
||||
//CVE-2016-10033, CVE-2016-10045: Don't pass -f if characters will be escaped.
|
||||
if ('' === $this->Sender) {
|
||||
$this->Sender = $this->From;
|
||||
}
|
||||
@ -1927,7 +1927,7 @@ class PHPMailer
|
||||
}
|
||||
|
||||
$callbacks = [];
|
||||
// Attempt to send to all recipients
|
||||
//Attempt to send to all recipients
|
||||
foreach ([$this->to, $this->cc, $this->bcc] as $togroup) {
|
||||
foreach ($togroup as $to) {
|
||||
if (!$this->smtp->recipient($to[0], $this->dsn)) {
|
||||
@ -1942,7 +1942,7 @@ class PHPMailer
|
||||
}
|
||||
}
|
||||
|
||||
// Only send the DATA command if we have viable recipients
|
||||
//Only send the DATA command if we have viable recipients
|
||||
if ((count($this->all_recipients) > count($bad_rcpt)) && !$this->smtp->data($header . $body)) {
|
||||
throw new Exception($this->lang('data_not_accepted'), self::STOP_CRITICAL);
|
||||
}
|
||||
@ -2004,7 +2004,7 @@ class PHPMailer
|
||||
$options = $this->SMTPOptions;
|
||||
}
|
||||
|
||||
// Already connected?
|
||||
//Already connected?
|
||||
if ($this->smtp->connected()) {
|
||||
return true;
|
||||
}
|
||||
@ -2026,14 +2026,14 @@ class PHPMailer
|
||||
)
|
||||
) {
|
||||
$this->edebug($this->lang('invalid_hostentry') . ' ' . trim($hostentry));
|
||||
// Not a valid host entry
|
||||
//Not a valid host entry
|
||||
continue;
|
||||
}
|
||||
// $hostinfo[1]: optional ssl or tls prefix
|
||||
// $hostinfo[2]: the hostname
|
||||
// $hostinfo[3]: optional port number
|
||||
// The host string prefix can temporarily override the current setting for SMTPSecure
|
||||
// If it's not specified, the default value is used
|
||||
//$hostinfo[1]: optional ssl or tls prefix
|
||||
//$hostinfo[2]: the hostname
|
||||
//$hostinfo[3]: optional port number
|
||||
//The host string prefix can temporarily override the current setting for SMTPSecure
|
||||
//If it's not specified, the default value is used
|
||||
|
||||
//Check the host name is a valid name or IP address before trying to use it
|
||||
if (!static::isValidHost($hostinfo[2])) {
|
||||
@ -2045,11 +2045,11 @@ class PHPMailer
|
||||
$tls = (static::ENCRYPTION_STARTTLS === $this->SMTPSecure);
|
||||
if ('ssl' === $hostinfo[1] || ('' === $hostinfo[1] && static::ENCRYPTION_SMTPS === $this->SMTPSecure)) {
|
||||
$prefix = 'ssl://';
|
||||
$tls = false; // Can't have SSL and TLS at the same time
|
||||
$tls = false; //Can't have SSL and TLS at the same time
|
||||
$secure = static::ENCRYPTION_SMTPS;
|
||||
} elseif ('tls' === $hostinfo[1]) {
|
||||
$tls = true;
|
||||
// tls doesn't use a prefix
|
||||
//TLS doesn't use a prefix
|
||||
$secure = static::ENCRYPTION_STARTTLS;
|
||||
}
|
||||
//Do we need the OpenSSL extension?
|
||||
@ -2079,10 +2079,10 @@ class PHPMailer
|
||||
}
|
||||
$this->smtp->hello($hello);
|
||||
//Automatically enable TLS encryption if:
|
||||
// * it's not disabled
|
||||
// * we have openssl extension
|
||||
// * we are not already using SSL
|
||||
// * the server offers STARTTLS
|
||||
//* it's not disabled
|
||||
//* we have openssl extension
|
||||
//* we are not already using SSL
|
||||
//* the server offers STARTTLS
|
||||
if ($this->SMTPAutoTLS && $sslext && 'ssl' !== $secure && $this->smtp->getServerExt('STARTTLS')) {
|
||||
$tls = true;
|
||||
}
|
||||
@ -2090,7 +2090,7 @@ class PHPMailer
|
||||
if (!$this->smtp->startTLS()) {
|
||||
throw new Exception($this->lang('connect_host'));
|
||||
}
|
||||
// We must resend EHLO after TLS negotiation
|
||||
//We must resend EHLO after TLS negotiation
|
||||
$this->smtp->hello($hello);
|
||||
}
|
||||
if (
|
||||
@ -2108,14 +2108,14 @@ class PHPMailer
|
||||
} catch (Exception $exc) {
|
||||
$lastexception = $exc;
|
||||
$this->edebug($exc->getMessage());
|
||||
// We must have connected, but then failed TLS or Auth, so close connection nicely
|
||||
//We must have connected, but then failed TLS or Auth, so close connection nicely
|
||||
$this->smtp->quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
// If we get here, all connection attempts have failed, so close connection hard
|
||||
//If we get here, all connection attempts have failed, so close connection hard
|
||||
$this->smtp->close();
|
||||
// As we've caught all exceptions, just report whatever the last one was
|
||||
//As we've caught all exceptions, just report whatever the last one was
|
||||
if ($this->exceptions && null !== $lastexception) {
|
||||
throw $lastexception;
|
||||
}
|
||||
@ -2146,7 +2146,7 @@ class PHPMailer
|
||||
*/
|
||||
public function setLanguage($langcode = 'en', $lang_path = '')
|
||||
{
|
||||
// Backwards compatibility for renamed language codes
|
||||
//Backwards compatibility for renamed language codes
|
||||
$renamed_langcodes = [
|
||||
'br' => 'pt_br',
|
||||
'cz' => 'cs',
|
||||
@ -2162,7 +2162,7 @@ class PHPMailer
|
||||
$langcode = $renamed_langcodes[$langcode];
|
||||
}
|
||||
|
||||
// Define full set of translatable strings in English
|
||||
//Define full set of translatable strings in English
|
||||
$PHPMAILER_LANG = [
|
||||
'authenticate' => 'SMTP Error: Could not authenticate.',
|
||||
'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
|
||||
@ -2187,7 +2187,7 @@ class PHPMailer
|
||||
'extension_missing' => 'Extension missing: ',
|
||||
];
|
||||
if (empty($lang_path)) {
|
||||
// Calculate an absolute path so it can work if CWD is not here
|
||||
//Calculate an absolute path so it can work if CWD is not here
|
||||
$lang_path = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
//Validate $langcode
|
||||
@ -2196,20 +2196,20 @@ class PHPMailer
|
||||
}
|
||||
$foundlang = true;
|
||||
$lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
|
||||
// There is no English translation file
|
||||
//There is no English translation file
|
||||
if ('en' !== $langcode) {
|
||||
// Make sure language file path is readable
|
||||
//Make sure language file path is readable
|
||||
if (!static::fileIsAccessible($lang_file)) {
|
||||
$foundlang = false;
|
||||
} else {
|
||||
// Overwrite language-specific strings.
|
||||
// This way we'll never have missing translation keys.
|
||||
//Overwrite language-specific strings.
|
||||
//This way we'll never have missing translation keys.
|
||||
$foundlang = include $lang_file;
|
||||
}
|
||||
}
|
||||
$this->language = $PHPMAILER_LANG;
|
||||
|
||||
return (bool) $foundlang; // Returns false if language not found
|
||||
return (bool) $foundlang; //Returns false if language not found
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2253,7 +2253,7 @@ class PHPMailer
|
||||
*/
|
||||
public function addrFormat($addr)
|
||||
{
|
||||
if (empty($addr[1])) { // No name provided
|
||||
if (empty($addr[1])) { //No name provided
|
||||
return $this->secureHeader($addr[0]);
|
||||
}
|
||||
|
||||
@ -2280,8 +2280,8 @@ class PHPMailer
|
||||
} else {
|
||||
$soft_break = static::$LE;
|
||||
}
|
||||
// If utf-8 encoding is used, we will need to make sure we don't
|
||||
// split multibyte characters when we wrap
|
||||
//If utf-8 encoding is used, we will need to make sure we don't
|
||||
//split multibyte characters when we wrap
|
||||
$is_utf8 = static::CHARSET_UTF8 === strtolower($this->CharSet);
|
||||
$lelen = strlen(static::$LE);
|
||||
$crlflen = strlen(static::$LE);
|
||||
@ -2381,29 +2381,29 @@ class PHPMailer
|
||||
$lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
|
||||
$encodedCharPos = strpos($lastChunk, '=');
|
||||
if (false !== $encodedCharPos) {
|
||||
// Found start of encoded character byte within $lookBack block.
|
||||
// Check the encoded byte value (the 2 chars after the '=')
|
||||
//Found start of encoded character byte within $lookBack block.
|
||||
//Check the encoded byte value (the 2 chars after the '=')
|
||||
$hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
|
||||
$dec = hexdec($hex);
|
||||
if ($dec < 128) {
|
||||
// Single byte character.
|
||||
// If the encoded char was found at pos 0, it will fit
|
||||
// otherwise reduce maxLength to start of the encoded char
|
||||
//Single byte character.
|
||||
//If the encoded char was found at pos 0, it will fit
|
||||
//otherwise reduce maxLength to start of the encoded char
|
||||
if ($encodedCharPos > 0) {
|
||||
$maxLength -= $lookBack - $encodedCharPos;
|
||||
}
|
||||
$foundSplitPos = true;
|
||||
} elseif ($dec >= 192) {
|
||||
// First byte of a multi byte character
|
||||
// Reduce maxLength to split at start of character
|
||||
//First byte of a multi byte character
|
||||
//Reduce maxLength to split at start of character
|
||||
$maxLength -= $lookBack - $encodedCharPos;
|
||||
$foundSplitPos = true;
|
||||
} elseif ($dec < 192) {
|
||||
// Middle byte of a multi byte character, look further back
|
||||
//Middle byte of a multi byte character, look further back
|
||||
$lookBack += 3;
|
||||
}
|
||||
} else {
|
||||
// No encoded character found
|
||||
//No encoded character found
|
||||
$foundSplitPos = true;
|
||||
}
|
||||
}
|
||||
@ -2447,7 +2447,7 @@ class PHPMailer
|
||||
|
||||
$result .= $this->headerLine('Date', '' === $this->MessageDate ? self::rfcDate() : $this->MessageDate);
|
||||
|
||||
// The To header is created automatically by mail(), so needs to be omitted here
|
||||
//The To header is created automatically by mail(), so needs to be omitted here
|
||||
if ('mail' !== $this->Mailer) {
|
||||
if ($this->SingleTo) {
|
||||
foreach ($this->to as $toaddr) {
|
||||
@ -2461,12 +2461,12 @@ class PHPMailer
|
||||
}
|
||||
$result .= $this->addrAppend('From', [[trim($this->From), $this->FromName]]);
|
||||
|
||||
// sendmail and mail() extract Cc from the header before sending
|
||||
//sendmail and mail() extract Cc from the header before sending
|
||||
if (count($this->cc) > 0) {
|
||||
$result .= $this->addrAppend('Cc', $this->cc);
|
||||
}
|
||||
|
||||
// sendmail and mail() extract Bcc from the header before sending
|
||||
//sendmail and mail() extract Bcc from the header before sending
|
||||
if (
|
||||
(
|
||||
'sendmail' === $this->Mailer || 'qmail' === $this->Mailer || 'mail' === $this->Mailer
|
||||
@ -2480,13 +2480,13 @@ class PHPMailer
|
||||
$result .= $this->addrAppend('Reply-To', $this->ReplyTo);
|
||||
}
|
||||
|
||||
// mail() sets the subject itself
|
||||
//mail() sets the subject itself
|
||||
if ('mail' !== $this->Mailer) {
|
||||
$result .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader($this->Subject)));
|
||||
}
|
||||
|
||||
// Only allow a custom message ID if it conforms to RFC 5322 section 3.6.4
|
||||
// https://tools.ietf.org/html/rfc5322#section-3.6.4
|
||||
//Only allow a custom message ID if it conforms to RFC 5322 section 3.6.4
|
||||
//https://tools.ietf.org/html/rfc5322#section-3.6.4
|
||||
if ('' !== $this->MessageID && preg_match('/^<.*@.*>$/', $this->MessageID)) {
|
||||
$this->lastMessageID = $this->MessageID;
|
||||
} else {
|
||||
@ -2512,7 +2512,7 @@ class PHPMailer
|
||||
$result .= $this->headerLine('Disposition-Notification-To', '<' . $this->ConfirmReadingTo . '>');
|
||||
}
|
||||
|
||||
// Add custom headers
|
||||
//Add custom headers
|
||||
foreach ($this->CustomHeader as $header) {
|
||||
$result .= $this->headerLine(
|
||||
trim($header[0]),
|
||||
@ -2554,19 +2554,19 @@ class PHPMailer
|
||||
$result .= $this->textLine(' boundary="' . $this->boundary[1] . '"');
|
||||
break;
|
||||
default:
|
||||
// Catches case 'plain': and case '':
|
||||
//Catches case 'plain': and case '':
|
||||
$result .= $this->textLine('Content-Type: ' . $this->ContentType . '; charset=' . $this->CharSet);
|
||||
$ismultipart = false;
|
||||
break;
|
||||
}
|
||||
// RFC1341 part 5 says 7bit is assumed if not specified
|
||||
//RFC1341 part 5 says 7bit is assumed if not specified
|
||||
if (static::ENCODING_7BIT !== $this->Encoding) {
|
||||
// RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE
|
||||
//RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE
|
||||
if ($ismultipart) {
|
||||
if (static::ENCODING_8BIT === $this->Encoding) {
|
||||
$result .= $this->headerLine('Content-Transfer-Encoding', static::ENCODING_8BIT);
|
||||
}
|
||||
// The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible
|
||||
//The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible
|
||||
} else {
|
||||
$result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
|
||||
}
|
||||
@ -2844,7 +2844,7 @@ class PHPMailer
|
||||
$body .= $this->attachAll('attachment', $this->boundary[1]);
|
||||
break;
|
||||
default:
|
||||
// Catch case 'plain' and case '', applies to simple `text/plain` and `text/html` body content types
|
||||
//Catch case 'plain' and case '', applies to simple `text/plain` and `text/html` body content types
|
||||
//Reset the `Encoding` property in case we changed it for line length reasons
|
||||
$this->Encoding = $bodyEncoding;
|
||||
$body .= $this->encodeString($this->Body, $this->Encoding);
|
||||
@ -2935,7 +2935,7 @@ class PHPMailer
|
||||
$result .= $this->textLine('--' . $boundary);
|
||||
$result .= sprintf('Content-Type: %s; charset=%s', $contentType, $charSet);
|
||||
$result .= static::$LE;
|
||||
// RFC1341 part 5 says 7bit is assumed if not specified
|
||||
//RFC1341 part 5 says 7bit is assumed if not specified
|
||||
if (static::ENCODING_7BIT !== $encoding) {
|
||||
$result .= $this->headerLine('Content-Transfer-Encoding', $encoding);
|
||||
}
|
||||
@ -3033,7 +3033,7 @@ class PHPMailer
|
||||
throw new Exception($this->lang('file_access') . $path, self::STOP_CONTINUE);
|
||||
}
|
||||
|
||||
// If a MIME type is not specified, try to work it out from the file name
|
||||
//If a MIME type is not specified, try to work it out from the file name
|
||||
if ('' === $type) {
|
||||
$type = static::filenameToType($path);
|
||||
}
|
||||
@ -3052,7 +3052,7 @@ class PHPMailer
|
||||
2 => $name,
|
||||
3 => $encoding,
|
||||
4 => $type,
|
||||
5 => false, // isStringAttachment
|
||||
5 => false, //isStringAttachment
|
||||
6 => $disposition,
|
||||
7 => $name,
|
||||
];
|
||||
@ -3092,16 +3092,16 @@ class PHPMailer
|
||||
*/
|
||||
protected function attachAll($disposition_type, $boundary)
|
||||
{
|
||||
// Return text of body
|
||||
//Return text of body
|
||||
$mime = [];
|
||||
$cidUniq = [];
|
||||
$incl = [];
|
||||
|
||||
// Add all attachments
|
||||
//Add all attachments
|
||||
foreach ($this->attachment as $attachment) {
|
||||
// Check if it is a valid disposition_filter
|
||||
//Check if it is a valid disposition_filter
|
||||
if ($attachment[6] === $disposition_type) {
|
||||
// Check for string attachment
|
||||
//Check for string attachment
|
||||
$string = '';
|
||||
$path = '';
|
||||
$bString = $attachment[5];
|
||||
@ -3142,7 +3142,7 @@ class PHPMailer
|
||||
static::$LE
|
||||
);
|
||||
}
|
||||
// RFC1341 part 5 says 7bit is assumed if not specified
|
||||
//RFC1341 part 5 says 7bit is assumed if not specified
|
||||
if (static::ENCODING_7BIT !== $encoding) {
|
||||
$mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, static::$LE);
|
||||
}
|
||||
@ -3152,7 +3152,7 @@ class PHPMailer
|
||||
$mime[] = 'Content-ID: <' . $this->encodeHeader($this->secureHeader($cid)) . '>' . static::$LE;
|
||||
}
|
||||
|
||||
// Allow for bypassing the Content-Disposition header
|
||||
//Allow for bypassing the Content-Disposition header
|
||||
if (!empty($disposition)) {
|
||||
$encoded_name = $this->encodeHeader($this->secureHeader($name));
|
||||
if (!empty($encoded_name)) {
|
||||
@ -3173,7 +3173,7 @@ class PHPMailer
|
||||
$mime[] = static::$LE;
|
||||
}
|
||||
|
||||
// Encode as string attachment
|
||||
//Encode as string attachment
|
||||
if ($bString) {
|
||||
$mime[] = $this->encodeString($string, $encoding);
|
||||
} else {
|
||||
@ -3249,7 +3249,7 @@ class PHPMailer
|
||||
case static::ENCODING_7BIT:
|
||||
case static::ENCODING_8BIT:
|
||||
$encoded = static::normalizeBreaks($str);
|
||||
// Make sure it ends with a line break
|
||||
//Make sure it ends with a line break
|
||||
if (substr($encoded, -(strlen(static::$LE))) !== static::$LE) {
|
||||
$encoded .= static::$LE;
|
||||
}
|
||||
@ -3287,7 +3287,7 @@ class PHPMailer
|
||||
switch (strtolower($position)) {
|
||||
case 'phrase':
|
||||
if (!preg_match('/[\200-\377]/', $str)) {
|
||||
// Can't use addslashes as we don't know the value of magic_quotes_sybase
|
||||
//Can't use addslashes as we don't know the value of magic_quotes_sybase
|
||||
$encoded = addcslashes($str, "\0..\37\177\\\"");
|
||||
if (($str === $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
|
||||
return $encoded;
|
||||
@ -3313,7 +3313,7 @@ class PHPMailer
|
||||
$charset = static::CHARSET_ASCII;
|
||||
}
|
||||
|
||||
// Q/B encoding adds 8 chars and the charset ("` =?<charset>?[QB]?<content>?=`").
|
||||
//Q/B encoding adds 8 chars and the charset ("` =?<charset>?[QB]?<content>?=`").
|
||||
$overhead = 8 + strlen($charset);
|
||||
|
||||
if ('mail' === $this->Mailer) {
|
||||
@ -3322,26 +3322,26 @@ class PHPMailer
|
||||
$maxlen = static::MAX_LINE_LENGTH - $overhead;
|
||||
}
|
||||
|
||||
// Select the encoding that produces the shortest output and/or prevents corruption.
|
||||
//Select the encoding that produces the shortest output and/or prevents corruption.
|
||||
if ($matchcount > strlen($str) / 3) {
|
||||
// More than 1/3 of the content needs encoding, use B-encode.
|
||||
//More than 1/3 of the content needs encoding, use B-encode.
|
||||
$encoding = 'B';
|
||||
} elseif ($matchcount > 0) {
|
||||
// Less than 1/3 of the content needs encoding, use Q-encode.
|
||||
//Less than 1/3 of the content needs encoding, use Q-encode.
|
||||
$encoding = 'Q';
|
||||
} elseif (strlen($str) > $maxlen) {
|
||||
// No encoding needed, but value exceeds max line length, use Q-encode to prevent corruption.
|
||||
//No encoding needed, but value exceeds max line length, use Q-encode to prevent corruption.
|
||||
$encoding = 'Q';
|
||||
} else {
|
||||
// No reformatting needed
|
||||
//No reformatting needed
|
||||
$encoding = false;
|
||||
}
|
||||
|
||||
switch ($encoding) {
|
||||
case 'B':
|
||||
if ($this->hasMultiBytes($str)) {
|
||||
// Use a custom function which correctly encodes and wraps long
|
||||
// multibyte strings without breaking lines within a character
|
||||
//Use a custom function which correctly encodes and wraps long
|
||||
//multibyte strings without breaking lines within a character
|
||||
$encoded = $this->base64EncodeWrapMB($str, "\n");
|
||||
} else {
|
||||
$encoded = base64_encode($str);
|
||||
@ -3376,7 +3376,7 @@ class PHPMailer
|
||||
return strlen($str) > mb_strlen($str, $this->CharSet);
|
||||
}
|
||||
|
||||
// Assume no multibytes (we can't handle without mbstring functions anyway)
|
||||
//Assume no multibytes (we can't handle without mbstring functions anyway)
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -3414,11 +3414,11 @@ class PHPMailer
|
||||
}
|
||||
|
||||
$mb_length = mb_strlen($str, $this->CharSet);
|
||||
// Each line must have length <= 75, including $start and $end
|
||||
//Each line must have length <= 75, including $start and $end
|
||||
$length = 75 - strlen($start) - strlen($end);
|
||||
// Average multi-byte ratio
|
||||
//Average multi-byte ratio
|
||||
$ratio = $mb_length / strlen($str);
|
||||
// Base64 has a 4:3 ratio
|
||||
//Base64 has a 4:3 ratio
|
||||
$avgLength = floor($length * $ratio * .75);
|
||||
|
||||
$offset = 0;
|
||||
@ -3433,7 +3433,7 @@ class PHPMailer
|
||||
$encoded .= $chunk . $linebreak;
|
||||
}
|
||||
|
||||
// Chomp the last linefeed
|
||||
//Chomp the last linefeed
|
||||
return substr($encoded, 0, -strlen($linebreak));
|
||||
}
|
||||
|
||||
@ -3462,12 +3462,12 @@ class PHPMailer
|
||||
*/
|
||||
public function encodeQ($str, $position = 'text')
|
||||
{
|
||||
// There should not be any EOL in the string
|
||||
//There should not be any EOL in the string
|
||||
$pattern = '';
|
||||
$encoded = str_replace(["\r", "\n"], '', $str);
|
||||
switch (strtolower($position)) {
|
||||
case 'phrase':
|
||||
// RFC 2047 section 5.3
|
||||
//RFC 2047 section 5.3
|
||||
$pattern = '^A-Za-z0-9!*+\/ -';
|
||||
break;
|
||||
/*
|
||||
@ -3480,15 +3480,15 @@ class PHPMailer
|
||||
/* Intentional fall through */
|
||||
case 'text':
|
||||
default:
|
||||
// RFC 2047 section 5.1
|
||||
// Replace every high ascii, control, =, ? and _ characters
|
||||
//RFC 2047 section 5.1
|
||||
//Replace every high ascii, control, =, ? and _ characters
|
||||
$pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
|
||||
break;
|
||||
}
|
||||
$matches = [];
|
||||
if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
|
||||
// If the string contains an '=', make sure it's the first thing we replace
|
||||
// so as to avoid double-encoding
|
||||
//If the string contains an '=', make sure it's the first thing we replace
|
||||
//so as to avoid double-encoding
|
||||
$eqkey = array_search('=', $matches[0], true);
|
||||
if (false !== $eqkey) {
|
||||
unset($matches[0][$eqkey]);
|
||||
@ -3498,8 +3498,8 @@ class PHPMailer
|
||||
$encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
|
||||
}
|
||||
}
|
||||
// Replace spaces with _ (more readable than =20)
|
||||
// RFC 2047 section 4.2(2)
|
||||
//Replace spaces with _ (more readable than =20)
|
||||
//RFC 2047 section 4.2(2)
|
||||
return str_replace(' ', '_', $encoded);
|
||||
}
|
||||
|
||||
@ -3526,7 +3526,7 @@ class PHPMailer
|
||||
$disposition = 'attachment'
|
||||
) {
|
||||
try {
|
||||
// If a MIME type is not specified, try to work it out from the file name
|
||||
//If a MIME type is not specified, try to work it out from the file name
|
||||
if ('' === $type) {
|
||||
$type = static::filenameToType($filename);
|
||||
}
|
||||
@ -3535,14 +3535,14 @@ class PHPMailer
|
||||
throw new Exception($this->lang('encoding') . $encoding);
|
||||
}
|
||||
|
||||
// Append to $attachment array
|
||||
//Append to $attachment array
|
||||
$this->attachment[] = [
|
||||
0 => $string,
|
||||
1 => $filename,
|
||||
2 => static::mb_pathinfo($filename, PATHINFO_BASENAME),
|
||||
3 => $encoding,
|
||||
4 => $type,
|
||||
5 => true, // isStringAttachment
|
||||
5 => true, //isStringAttachment
|
||||
6 => $disposition,
|
||||
7 => 0,
|
||||
];
|
||||
@ -3593,7 +3593,7 @@ class PHPMailer
|
||||
throw new Exception($this->lang('file_access') . $path, self::STOP_CONTINUE);
|
||||
}
|
||||
|
||||
// If a MIME type is not specified, try to work it out from the file name
|
||||
//If a MIME type is not specified, try to work it out from the file name
|
||||
if ('' === $type) {
|
||||
$type = static::filenameToType($path);
|
||||
}
|
||||
@ -3607,14 +3607,14 @@ class PHPMailer
|
||||
$name = $filename;
|
||||
}
|
||||
|
||||
// Append to $attachment array
|
||||
//Append to $attachment array
|
||||
$this->attachment[] = [
|
||||
0 => $path,
|
||||
1 => $filename,
|
||||
2 => $name,
|
||||
3 => $encoding,
|
||||
4 => $type,
|
||||
5 => false, // isStringAttachment
|
||||
5 => false, //isStringAttachment
|
||||
6 => $disposition,
|
||||
7 => $cid,
|
||||
];
|
||||
@ -3659,7 +3659,7 @@ class PHPMailer
|
||||
$disposition = 'inline'
|
||||
) {
|
||||
try {
|
||||
// If a MIME type is not specified, try to work it out from the name
|
||||
//If a MIME type is not specified, try to work it out from the name
|
||||
if ('' === $type && !empty($name)) {
|
||||
$type = static::filenameToType($name);
|
||||
}
|
||||
@ -3668,14 +3668,14 @@ class PHPMailer
|
||||
throw new Exception($this->lang('encoding') . $encoding);
|
||||
}
|
||||
|
||||
// Append to $attachment array
|
||||
//Append to $attachment array
|
||||
$this->attachment[] = [
|
||||
0 => $string,
|
||||
1 => $name,
|
||||
2 => $name,
|
||||
3 => $encoding,
|
||||
4 => $type,
|
||||
5 => true, // isStringAttachment
|
||||
5 => true, //isStringAttachment
|
||||
6 => $disposition,
|
||||
7 => $cid,
|
||||
];
|
||||
@ -3895,8 +3895,8 @@ class PHPMailer
|
||||
*/
|
||||
public static function rfcDate()
|
||||
{
|
||||
// Set the time zone to whatever the default is to avoid 500 errors
|
||||
// Will default to UTC if it's not set properly in php.ini
|
||||
//Set the time zone to whatever the default is to avoid 500 errors
|
||||
//Will default to UTC if it's not set properly in php.ini
|
||||
date_default_timezone_set(@date_default_timezone_get());
|
||||
|
||||
return date('D, j M Y H:i:s O');
|
||||
@ -3974,13 +3974,13 @@ class PHPMailer
|
||||
protected function lang($key)
|
||||
{
|
||||
if (count($this->language) < 1) {
|
||||
$this->setLanguage(); // set the default language
|
||||
$this->setLanguage(); //Set the default language
|
||||
}
|
||||
|
||||
if (array_key_exists($key, $this->language)) {
|
||||
if ('smtp_connect_failed' === $key) {
|
||||
//Include a link to troubleshooting docs on SMTP connection failure
|
||||
//this is by far the biggest cause of support questions
|
||||
//Include a link to troubleshooting docs on SMTP connection failure.
|
||||
//This is by far the biggest cause of support questions
|
||||
//but it's usually not PHPMailer's fault.
|
||||
return $this->language[$key] . ' https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting';
|
||||
}
|
||||
@ -4015,7 +4015,7 @@ class PHPMailer
|
||||
public function addCustomHeader($name, $value = null)
|
||||
{
|
||||
if (null === $value && strpos($name, ':') !== false) {
|
||||
// Value passed in as name:value
|
||||
//Value passed in as name:value
|
||||
list($name, $value) = explode(':', $name, 2);
|
||||
}
|
||||
$name = trim($name);
|
||||
@ -4069,11 +4069,11 @@ class PHPMailer
|
||||
preg_match_all('/(?<!-)(src|background)=["\'](.*)["\']/Ui', $message, $images);
|
||||
if (array_key_exists(2, $images)) {
|
||||
if (strlen($basedir) > 1 && '/' !== substr($basedir, -1)) {
|
||||
// Ensure $basedir has a trailing /
|
||||
//Ensure $basedir has a trailing /
|
||||
$basedir .= '/';
|
||||
}
|
||||
foreach ($images[2] as $imgindex => $url) {
|
||||
// Convert data URIs into embedded images
|
||||
//Convert data URIs into embedded images
|
||||
//e.g. "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
|
||||
$match = [];
|
||||
if (preg_match('#^data:(image/(?:jpe?g|gif|png));?(base64)?,(.+)#', $url, $match)) {
|
||||
@ -4087,7 +4087,7 @@ class PHPMailer
|
||||
}
|
||||
//Hash the decoded data, not the URL, so that the same data-URI image used in multiple places
|
||||
//will only be embedded once, even if it used a different encoding
|
||||
$cid = substr(hash('sha256', $data), 0, 32) . '@phpmailer.0'; // RFC2392 S 2
|
||||
$cid = substr(hash('sha256', $data), 0, 32) . '@phpmailer.0'; //RFC2392 S 2
|
||||
|
||||
if (!$this->cidExists($cid)) {
|
||||
$this->addStringEmbeddedImage(
|
||||
@ -4106,13 +4106,13 @@ class PHPMailer
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
// Only process relative URLs if a basedir is provided (i.e. no absolute local paths)
|
||||
//Only process relative URLs if a basedir is provided (i.e. no absolute local paths)
|
||||
!empty($basedir)
|
||||
// Ignore URLs containing parent dir traversal (..)
|
||||
//Ignore URLs containing parent dir traversal (..)
|
||||
&& (strpos($url, '..') === false)
|
||||
// Do not change urls that are already inline images
|
||||
//Do not change urls that are already inline images
|
||||
&& 0 !== strpos($url, 'cid:')
|
||||
// Do not change absolute URLs, including anonymous protocol
|
||||
//Do not change absolute URLs, including anonymous protocol
|
||||
&& !preg_match('#^[a-z][a-z0-9+.-]*:?//#i', $url)
|
||||
) {
|
||||
$filename = static::mb_pathinfo($url, PATHINFO_BASENAME);
|
||||
@ -4120,7 +4120,7 @@ class PHPMailer
|
||||
if ('.' === $directory) {
|
||||
$directory = '';
|
||||
}
|
||||
// RFC2392 S 2
|
||||
//RFC2392 S 2
|
||||
$cid = substr(hash('sha256', $url), 0, 32) . '@phpmailer.0';
|
||||
if (strlen($basedir) > 1 && '/' !== substr($basedir, -1)) {
|
||||
$basedir .= '/';
|
||||
@ -4147,7 +4147,7 @@ class PHPMailer
|
||||
}
|
||||
}
|
||||
$this->isHTML();
|
||||
// Convert all message body line breaks to LE, makes quoted-printable encoding work much better
|
||||
//Convert all message body line breaks to LE, makes quoted-printable encoding work much better
|
||||
$this->Body = static::normalizeBreaks($message);
|
||||
$this->AltBody = static::normalizeBreaks($this->html2text($message, $advanced));
|
||||
if (!$this->alternativeExists()) {
|
||||
@ -4166,9 +4166,9 @@ class PHPMailer
|
||||
* Example usage:
|
||||
*
|
||||
* ```php
|
||||
* // Use default conversion
|
||||
* //Use default conversion
|
||||
* $plain = $mail->html2text($html);
|
||||
* // Use your own custom converter
|
||||
* //Use your own custom converter
|
||||
* $plain = $mail->html2text($html, function($html) {
|
||||
* $converter = new MyHtml2text($html);
|
||||
* return $converter->get_text();
|
||||
@ -4335,7 +4335,7 @@ class PHPMailer
|
||||
*/
|
||||
public static function filenameToType($filename)
|
||||
{
|
||||
// In case the path is a URL, strip any query string before getting extension
|
||||
//In case the path is a URL, strip any query string before getting extension
|
||||
$qpos = strpos($filename, '?');
|
||||
if (false !== $qpos) {
|
||||
$filename = substr($filename, 0, $qpos);
|
||||
@ -4446,9 +4446,9 @@ class PHPMailer
|
||||
if (null === $breaktype) {
|
||||
$breaktype = static::$LE;
|
||||
}
|
||||
// Normalise to \n
|
||||
//Normalise to \n
|
||||
$text = str_replace([self::CRLF, "\r"], "\n", $text);
|
||||
// Now convert LE as needed
|
||||
//Now convert LE as needed
|
||||
if ("\n" !== $breaktype) {
|
||||
$text = str_replace("\n", $breaktype, $text);
|
||||
}
|
||||
@ -4627,7 +4627,7 @@ class PHPMailer
|
||||
if (empty($body)) {
|
||||
return self::CRLF;
|
||||
}
|
||||
// Normalize line endings to CRLF
|
||||
//Normalize line endings to CRLF
|
||||
$body = static::normalizeBreaks($body, self::CRLF);
|
||||
|
||||
//Reduce multiple trailing line breaks to a single one
|
||||
@ -4647,9 +4647,9 @@ class PHPMailer
|
||||
*/
|
||||
public function DKIM_Add($headers_line, $subject, $body)
|
||||
{
|
||||
$DKIMsignatureType = 'rsa-sha256'; // Signature & hash algorithms
|
||||
$DKIMcanonicalization = 'relaxed/simple'; // Canonicalization methods of header & body
|
||||
$DKIMquery = 'dns/txt'; // Query method
|
||||
$DKIMsignatureType = 'rsa-sha256'; //Signature & hash algorithms
|
||||
$DKIMcanonicalization = 'relaxed/simple'; //Canonicalization methods of header & body
|
||||
$DKIMquery = 'dns/txt'; //Query method
|
||||
$DKIMtime = time();
|
||||
//Always sign these headers without being asked
|
||||
//Recommended list from https://tools.ietf.org/html/rfc6376#section-5.4.1
|
||||
@ -4750,7 +4750,8 @@ class PHPMailer
|
||||
$headerKeys = ' h=' . implode(':', $headersToSignKeys) . ';' . static::$LE;
|
||||
$headerValues = implode(static::$LE, $headersToSign);
|
||||
$body = $this->DKIM_BodyC($body);
|
||||
$DKIMb64 = base64_encode(pack('H*', hash('sha256', $body))); // Base64 of packed binary SHA-256 hash of body
|
||||
//Base64 of packed binary SHA-256 hash of body
|
||||
$DKIMb64 = base64_encode(pack('H*', hash('sha256', $body)));
|
||||
$ident = '';
|
||||
if ('' !== $this->DKIM_identity) {
|
||||
$ident = ' i=' . $this->DKIM_identity . ';' . static::$LE;
|
||||
|
42
src/POP3.php
42
src/POP3.php
@ -199,13 +199,13 @@ class POP3
|
||||
public function authorise($host, $port = false, $timeout = false, $username = '', $password = '', $debug_level = 0)
|
||||
{
|
||||
$this->host = $host;
|
||||
// If no port value provided, use default
|
||||
//If no port value provided, use default
|
||||
if (false === $port) {
|
||||
$this->port = static::DEFAULT_PORT;
|
||||
} else {
|
||||
$this->port = (int) $port;
|
||||
}
|
||||
// If no timeout value provided, use default
|
||||
//If no timeout value provided, use default
|
||||
if (false === $timeout) {
|
||||
$this->tval = static::DEFAULT_TIMEOUT;
|
||||
} else {
|
||||
@ -214,9 +214,9 @@ class POP3
|
||||
$this->do_debug = $debug_level;
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
// Reset the error log
|
||||
//Reset the error log
|
||||
$this->errors = [];
|
||||
// connect
|
||||
//Connect
|
||||
$result = $this->connect($this->host, $this->port, $this->tval);
|
||||
if ($result) {
|
||||
$login_result = $this->login($this->username, $this->password);
|
||||
@ -226,7 +226,7 @@ class POP3
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// We need to disconnect regardless of whether the login succeeded
|
||||
//We need to disconnect regardless of whether the login succeeded
|
||||
$this->disconnect();
|
||||
|
||||
return false;
|
||||
@ -243,7 +243,7 @@ class POP3
|
||||
*/
|
||||
public function connect($host, $port = false, $tval = 30)
|
||||
{
|
||||
// Are we already connected?
|
||||
//Are we already connected?
|
||||
if ($this->connected) {
|
||||
return true;
|
||||
}
|
||||
@ -256,22 +256,22 @@ class POP3
|
||||
$port = static::DEFAULT_PORT;
|
||||
}
|
||||
|
||||
// connect to the POP3 server
|
||||
//Connect to the POP3 server
|
||||
$errno = 0;
|
||||
$errstr = '';
|
||||
$this->pop_conn = fsockopen(
|
||||
$host, // POP3 Host
|
||||
$port, // Port #
|
||||
$errno, // Error Number
|
||||
$errstr, // Error Message
|
||||
$host, //POP3 Host
|
||||
$port, //Port #
|
||||
$errno, //Error Number
|
||||
$errstr, //Error Message
|
||||
$tval
|
||||
); // Timeout (seconds)
|
||||
// Restore the error handler
|
||||
); //Timeout (seconds)
|
||||
//Restore the error handler
|
||||
restore_error_handler();
|
||||
|
||||
// Did we connect?
|
||||
//Did we connect?
|
||||
if (false === $this->pop_conn) {
|
||||
// It would appear not...
|
||||
//It would appear not...
|
||||
$this->setError(
|
||||
"Failed to connect to server $host on port $port. errno: $errno; errstr: $errstr"
|
||||
);
|
||||
@ -279,14 +279,14 @@ class POP3
|
||||
return false;
|
||||
}
|
||||
|
||||
// Increase the stream time-out
|
||||
//Increase the stream time-out
|
||||
stream_set_timeout($this->pop_conn, $tval, 0);
|
||||
|
||||
// Get the POP3 server response
|
||||
//Get the POP3 server response
|
||||
$pop3_response = $this->getResponse();
|
||||
// Check for the +OK
|
||||
//Check for the +OK
|
||||
if ($this->checkResponse($pop3_response)) {
|
||||
// The connection is established and the POP3 server is talking
|
||||
//The connection is established and the POP3 server is talking
|
||||
$this->connected = true;
|
||||
|
||||
return true;
|
||||
@ -316,11 +316,11 @@ class POP3
|
||||
$password = $this->password;
|
||||
}
|
||||
|
||||
// Send the Username
|
||||
//Send the Username
|
||||
$this->sendString("USER $username" . static::LE);
|
||||
$pop3_response = $this->getResponse();
|
||||
if ($this->checkResponse($pop3_response)) {
|
||||
// Send the Password
|
||||
//Send the Password
|
||||
$this->sendString("PASS $password" . static::LE);
|
||||
$pop3_response = $this->getResponse();
|
||||
if ($this->checkResponse($pop3_response)) {
|
||||
|
82
src/SMTP.php
82
src/SMTP.php
@ -312,11 +312,11 @@ class SMTP
|
||||
*/
|
||||
public function connect($host, $port = null, $timeout = 30, $options = [])
|
||||
{
|
||||
// Clear errors to avoid confusion
|
||||
//Clear errors to avoid confusion
|
||||
$this->setError('');
|
||||
// Make sure we are __not__ connected
|
||||
//Make sure we are __not__ connected
|
||||
if ($this->connected()) {
|
||||
// Already connected, generate error
|
||||
//Already connected, generate error
|
||||
$this->setError('Already connected to a server');
|
||||
|
||||
return false;
|
||||
@ -324,7 +324,7 @@ class SMTP
|
||||
if (empty($port)) {
|
||||
$port = self::DEFAULT_PORT;
|
||||
}
|
||||
// Connect to the SMTP server
|
||||
//Connect to the SMTP server
|
||||
$this->edebug(
|
||||
"Connection: opening to $host:$port, timeout=$timeout, options=" .
|
||||
(count($options) > 0 ? var_export($options, true) : 'array()'),
|
||||
@ -340,7 +340,7 @@ class SMTP
|
||||
|
||||
$this->edebug('Connection: opened', self::DEBUG_CONNECTION);
|
||||
|
||||
// Get any announcement
|
||||
//Get any announcement
|
||||
$this->last_reply = $this->get_lines();
|
||||
$this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
|
||||
$responseCode = (int)substr($this->last_reply, 0, 3);
|
||||
@ -409,7 +409,7 @@ class SMTP
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
// Verify we connected properly
|
||||
//Verify we connected properly
|
||||
if (!is_resource($connection)) {
|
||||
$this->setError(
|
||||
'Failed to connect to server',
|
||||
@ -426,11 +426,11 @@ class SMTP
|
||||
return false;
|
||||
}
|
||||
|
||||
// SMTP server can take longer to respond, give longer timeout for first read
|
||||
// Windows does not have support for this timeout function
|
||||
//SMTP server can take longer to respond, give longer timeout for first read
|
||||
//Windows does not have support for this timeout function
|
||||
if (strpos(PHP_OS, 'WIN') !== 0) {
|
||||
$max = (int)ini_get('max_execution_time');
|
||||
// Don't bother if unlimited, or if set_time_limit is disabled
|
||||
//Don't bother if unlimited, or if set_time_limit is disabled
|
||||
if (0 !== $max && $timeout > $max && strpos(ini_get('disable_functions'), 'set_time_limit') === false) {
|
||||
@set_time_limit($timeout);
|
||||
}
|
||||
@ -461,7 +461,7 @@ class SMTP
|
||||
$crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
|
||||
}
|
||||
|
||||
// Begin encrypted connection
|
||||
//Begin encrypted connection
|
||||
set_error_handler([$this, 'errorHandler']);
|
||||
$crypto_ok = stream_socket_enable_crypto(
|
||||
$this->smtp_conn,
|
||||
@ -499,11 +499,11 @@ class SMTP
|
||||
}
|
||||
|
||||
if (array_key_exists('EHLO', $this->server_caps)) {
|
||||
// SMTP extensions are available; try to find a proper authentication method
|
||||
//SMTP extensions are available; try to find a proper authentication method
|
||||
if (!array_key_exists('AUTH', $this->server_caps)) {
|
||||
$this->setError('Authentication is not allowed at this stage');
|
||||
// 'at this stage' means that auth may be allowed after the stage changes
|
||||
// e.g. after STARTTLS
|
||||
//'at this stage' means that auth may be allowed after the stage changes
|
||||
//e.g. after STARTTLS
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -547,11 +547,11 @@ class SMTP
|
||||
}
|
||||
switch ($authtype) {
|
||||
case 'PLAIN':
|
||||
// Start authentication
|
||||
//Start authentication
|
||||
if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) {
|
||||
return false;
|
||||
}
|
||||
// Send encoded username and password
|
||||
//Send encoded username and password
|
||||
if (
|
||||
!$this->sendCommand(
|
||||
'User & Password',
|
||||
@ -563,7 +563,7 @@ class SMTP
|
||||
}
|
||||
break;
|
||||
case 'LOGIN':
|
||||
// Start authentication
|
||||
//Start authentication
|
||||
if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) {
|
||||
return false;
|
||||
}
|
||||
@ -575,17 +575,17 @@ class SMTP
|
||||
}
|
||||
break;
|
||||
case 'CRAM-MD5':
|
||||
// Start authentication
|
||||
//Start authentication
|
||||
if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) {
|
||||
return false;
|
||||
}
|
||||
// Get the challenge
|
||||
//Get the challenge
|
||||
$challenge = base64_decode(substr($this->last_reply, 4));
|
||||
|
||||
// Build the response
|
||||
//Build the response
|
||||
$response = $username . ' ' . $this->hmac($challenge, $password);
|
||||
|
||||
// send encoded credentials
|
||||
//send encoded credentials
|
||||
return $this->sendCommand('Username', base64_encode($response), 235);
|
||||
case 'XOAUTH2':
|
||||
//The OAuth instance must be set up prior to requesting auth.
|
||||
@ -594,7 +594,7 @@ class SMTP
|
||||
}
|
||||
$oauth = $OAuth->getOauth64();
|
||||
|
||||
// Start authentication
|
||||
//Start authentication
|
||||
if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 ' . $oauth, 235)) {
|
||||
return false;
|
||||
}
|
||||
@ -624,15 +624,15 @@ class SMTP
|
||||
return hash_hmac('md5', $data, $key);
|
||||
}
|
||||
|
||||
// The following borrowed from
|
||||
// http://php.net/manual/en/function.mhash.php#27225
|
||||
//The following borrowed from
|
||||
//http://php.net/manual/en/function.mhash.php#27225
|
||||
|
||||
// RFC 2104 HMAC implementation for php.
|
||||
// Creates an md5 HMAC.
|
||||
// Eliminates the need to install mhash to compute a HMAC
|
||||
// by Lance Rushing
|
||||
//RFC 2104 HMAC implementation for php.
|
||||
//Creates an md5 HMAC.
|
||||
//Eliminates the need to install mhash to compute a HMAC
|
||||
//by Lance Rushing
|
||||
|
||||
$bytelen = 64; // byte length for md5
|
||||
$bytelen = 64; //byte length for md5
|
||||
if (strlen($key) > $bytelen) {
|
||||
$key = pack('H*', md5($key));
|
||||
}
|
||||
@ -655,7 +655,7 @@ class SMTP
|
||||
if (is_resource($this->smtp_conn)) {
|
||||
$sock_status = stream_get_meta_data($this->smtp_conn);
|
||||
if ($sock_status['eof']) {
|
||||
// The socket is valid but we are not connected
|
||||
//The socket is valid but we are not connected
|
||||
$this->edebug(
|
||||
'SMTP NOTICE: EOF caught while checking if connected',
|
||||
self::DEBUG_CLIENT
|
||||
@ -665,7 +665,7 @@ class SMTP
|
||||
return false;
|
||||
}
|
||||
|
||||
return true; // everything looks good
|
||||
return true; //everything looks good
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -683,7 +683,7 @@ class SMTP
|
||||
$this->server_caps = null;
|
||||
$this->helo_rply = null;
|
||||
if (is_resource($this->smtp_conn)) {
|
||||
// close the connection and cleanup
|
||||
//Close the connection and cleanup
|
||||
fclose($this->smtp_conn);
|
||||
$this->smtp_conn = null; //Makes for cleaner serialization
|
||||
$this->edebug('Connection: closed', self::DEBUG_CONNECTION);
|
||||
@ -718,7 +718,7 @@ class SMTP
|
||||
* NOTE: this does not count towards line-length limit.
|
||||
*/
|
||||
|
||||
// Normalize line breaks before exploding
|
||||
//Normalize line breaks before exploding
|
||||
$lines = explode("\n", str_replace(["\r\n", "\r"], "\n", $msg_data));
|
||||
|
||||
/* To distinguish between a complete RFC822 message and a plain message body, we check if the first field
|
||||
@ -998,12 +998,12 @@ class SMTP
|
||||
$this->client_send($commandstring . static::LE, $command);
|
||||
|
||||
$this->last_reply = $this->get_lines();
|
||||
// Fetch SMTP code and possible error code explanation
|
||||
//Fetch SMTP code and possible error code explanation
|
||||
$matches = [];
|
||||
if (preg_match('/^([\d]{3})[ -](?:([\d]\\.[\d]\\.[\d]{1,2}) )?/', $this->last_reply, $matches)) {
|
||||
$code = (int) $matches[1];
|
||||
$code_ex = (count($matches) > 2 ? $matches[2] : null);
|
||||
// Cut off error code from each response line
|
||||
//Cut off error code from each response line
|
||||
$detail = preg_replace(
|
||||
"/{$code}[ -]" .
|
||||
($code_ex ? str_replace('.', '\\.', $code_ex) . ' ' : '') . '/m',
|
||||
@ -1011,7 +1011,7 @@ class SMTP
|
||||
$this->last_reply
|
||||
);
|
||||
} else {
|
||||
// Fall back to simple parsing if regex fails
|
||||
//Fall back to simple parsing if regex fails
|
||||
$code = (int) substr($this->last_reply, 0, 3);
|
||||
$code_ex = null;
|
||||
$detail = substr($this->last_reply, 4);
|
||||
@ -1206,7 +1206,7 @@ class SMTP
|
||||
*/
|
||||
protected function get_lines()
|
||||
{
|
||||
// If the connection is bad, give up straight away
|
||||
//If the connection is bad, give up straight away
|
||||
if (!is_resource($this->smtp_conn)) {
|
||||
return '';
|
||||
}
|
||||
@ -1259,13 +1259,13 @@ class SMTP
|
||||
$str = @fgets($this->smtp_conn, self::MAX_REPLY_LENGTH);
|
||||
$this->edebug('SMTP INBOUND: "' . trim($str) . '"', self::DEBUG_LOWLEVEL);
|
||||
$data .= $str;
|
||||
// If response is only 3 chars (not valid, but RFC5321 S4.2 says it must be handled),
|
||||
// or 4th character is a space or a line break char, we are done reading, break the loop.
|
||||
// String array access is a significant micro-optimisation over strlen
|
||||
//If response is only 3 chars (not valid, but RFC5321 S4.2 says it must be handled),
|
||||
//or 4th character is a space or a line break char, we are done reading, break the loop.
|
||||
//String array access is a significant micro-optimisation over strlen
|
||||
if (!isset($str[3]) || $str[3] === ' ' || $str[3] === "\r" || $str[3] === "\n") {
|
||||
break;
|
||||
}
|
||||
// Timed-out? Log and break
|
||||
//Timed-out? Log and break
|
||||
$info = stream_get_meta_data($this->smtp_conn);
|
||||
if ($info['timed_out']) {
|
||||
$this->edebug(
|
||||
@ -1274,7 +1274,7 @@ class SMTP
|
||||
);
|
||||
break;
|
||||
}
|
||||
// Now check if reads took too long
|
||||
//Now check if reads took too long
|
||||
if ($endtime && time() > $endtime) {
|
||||
$this->edebug(
|
||||
'SMTP -> get_lines(): timelimit reached (' .
|
||||
|
@ -136,7 +136,7 @@ final class PHPMailerTest extends TestCase
|
||||
*/
|
||||
protected function tear_down()
|
||||
{
|
||||
// Clean global variables
|
||||
//Clean global variables
|
||||
$this->Mail = null;
|
||||
$this->ChangeLog = [];
|
||||
$this->NoteLog = [];
|
||||
@ -154,7 +154,7 @@ final class PHPMailerTest extends TestCase
|
||||
{
|
||||
$this->checkChanges();
|
||||
|
||||
// Determine line endings for message
|
||||
//Determine line endings for message
|
||||
if ('text/html' === $this->Mail->ContentType || $this->Mail->AltBody !== '') {
|
||||
$eol = "<br>\r\n";
|
||||
$bullet_start = '<li>';
|
||||
@ -182,7 +182,7 @@ final class PHPMailerTest extends TestCase
|
||||
$ReportBody .= 'Host: ' . $this->Mail->Host . $eol;
|
||||
}
|
||||
|
||||
// If attachments then create an attachment list
|
||||
//If attachments then create an attachment list
|
||||
$attachments = $this->Mail->getAttachments();
|
||||
if (count($attachments) > 0) {
|
||||
$ReportBody .= 'Attachments:' . $eol;
|
||||
@ -195,7 +195,7 @@ final class PHPMailerTest extends TestCase
|
||||
$ReportBody .= $list_end . $eol;
|
||||
}
|
||||
|
||||
// If there are changes then list them
|
||||
//If there are changes then list them
|
||||
if (count($this->ChangeLog) > 0) {
|
||||
$ReportBody .= 'Changes' . $eol;
|
||||
$ReportBody .= '-------' . $eol;
|
||||
@ -208,7 +208,7 @@ final class PHPMailerTest extends TestCase
|
||||
$ReportBody .= $list_end . $eol . $eol;
|
||||
}
|
||||
|
||||
// If there are notes then list them
|
||||
//If there are notes then list them
|
||||
if (count($this->NoteLog) > 0) {
|
||||
$ReportBody .= 'Notes' . $eol;
|
||||
$ReportBody .= '-----' . $eol;
|
||||
@ -220,7 +220,7 @@ final class PHPMailerTest extends TestCase
|
||||
$ReportBody .= $list_end;
|
||||
}
|
||||
|
||||
// Re-attach the original body
|
||||
//Re-attach the original body
|
||||
$this->Mail->Body .= $eol . $ReportBody;
|
||||
}
|
||||
|
||||
@ -633,7 +633,7 @@ final class PHPMailerTest extends TestCase
|
||||
"(\r\n RCPT TO:user@example.com\r\n DATA \\\nSubject: spam10\\\n\r\n Hello," .
|
||||
"\r\n this is a spam mail.\\\n.\r\n QUIT\r\n ) a@example.net",
|
||||
];
|
||||
// IDNs in Unicode and ASCII forms.
|
||||
//IDNs in Unicode and ASCII forms.
|
||||
$unicodeaddresses = [
|
||||
'first.last@bücher.ch',
|
||||
'first.last@кто.рф',
|
||||
@ -1057,7 +1057,7 @@ EOT;
|
||||
//This file is in ISO-8859-1 charset
|
||||
//Needs to be external because this file is in UTF-8
|
||||
$content = file_get_contents(realpath($this->INCLUDE_DIR . '/examples/contents.html'));
|
||||
// This is the string 'éèîüçÅñæß' in ISO-8859-1, base-64 encoded
|
||||
//This is the string 'éèîüçÅñæß' in ISO-8859-1, base-64 encoded
|
||||
$check = base64_decode('6eju/OfF8ebf');
|
||||
//Make sure it really is in ISO-8859-1!
|
||||
$this->Mail->msgHTML(
|
||||
@ -2669,7 +2669,7 @@ EOT;
|
||||
$this->Mail->clearAllRecipients();
|
||||
$this->Mail->clearReplyTos();
|
||||
|
||||
// This file is UTF-8 encoded. Create a domain encoded in "iso-8859-1".
|
||||
//This file is UTF-8 encoded. Create a domain encoded in "iso-8859-1".
|
||||
$letter = html_entity_decode('ç', ENT_COMPAT, PHPMailer::CHARSET_ISO88591);
|
||||
$domain = '@' . 'fran' . $letter . 'ois.ch';
|
||||
$this->Mail->addAddress('test' . $domain);
|
||||
@ -2677,19 +2677,19 @@ EOT;
|
||||
$this->Mail->addBCC('test+bcc' . $domain);
|
||||
$this->Mail->addReplyTo('test+replyto' . $domain);
|
||||
|
||||
// Queued addresses are not returned by get*Addresses() before send() call.
|
||||
//Queued addresses are not returned by get*Addresses() before send() call.
|
||||
self::assertEmpty($this->Mail->getToAddresses(), 'Bad "to" recipients');
|
||||
self::assertEmpty($this->Mail->getCcAddresses(), 'Bad "cc" recipients');
|
||||
self::assertEmpty($this->Mail->getBccAddresses(), 'Bad "bcc" recipients');
|
||||
self::assertEmpty($this->Mail->getReplyToAddresses(), 'Bad "reply-to" recipients');
|
||||
|
||||
// Clear queued BCC recipient.
|
||||
//Clear queued BCC recipient.
|
||||
$this->Mail->clearBCCs();
|
||||
|
||||
$this->buildBody();
|
||||
self::assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
|
||||
|
||||
// Addresses with IDN are returned by get*Addresses() after send() call.
|
||||
//Addresses with IDN are returned by get*Addresses() after send() call.
|
||||
$domain = $this->Mail->punyencodeAddress($domain);
|
||||
self::assertEquals(
|
||||
[['test' . $domain, '']],
|
||||
@ -2742,7 +2742,7 @@ EOT;
|
||||
$this->buildBody();
|
||||
self::assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
|
||||
|
||||
// There should be only one "To" address and one "Reply-To" address.
|
||||
//There should be only one "To" address and one "Reply-To" address.
|
||||
self::assertCount(
|
||||
1,
|
||||
$this->Mail->getToAddresses(),
|
||||
@ -2821,24 +2821,24 @@ EOT;
|
||||
self::assertTrue($this->Mail->smtpConnect(), 'SMTP single connect failed');
|
||||
$this->Mail->smtpClose();
|
||||
|
||||
// $this->Mail->Host = 'localhost:12345;10.10.10.10:54321;' . $_REQUEST['mail_host'];
|
||||
// self::assertTrue($this->Mail->smtpConnect(), 'SMTP multi-connect failed');
|
||||
// $this->Mail->smtpClose();
|
||||
// $this->Mail->Host = '[::1]:' . $this->Mail->Port . ';' . $_REQUEST['mail_host'];
|
||||
// self::assertTrue($this->Mail->smtpConnect(), 'SMTP IPv6 literal multi-connect failed');
|
||||
// $this->Mail->smtpClose();
|
||||
//$this->Mail->Host = 'localhost:12345;10.10.10.10:54321;' . $_REQUEST['mail_host'];
|
||||
//self::assertTrue($this->Mail->smtpConnect(), 'SMTP multi-connect failed');
|
||||
//$this->Mail->smtpClose();
|
||||
//$this->Mail->Host = '[::1]:' . $this->Mail->Port . ';' . $_REQUEST['mail_host'];
|
||||
//self::assertTrue($this->Mail->smtpConnect(), 'SMTP IPv6 literal multi-connect failed');
|
||||
//$this->Mail->smtpClose();
|
||||
|
||||
// All these hosts are expected to fail
|
||||
// $this->Mail->Host = 'xyz://bogus:25;tls://[bogus]:25;ssl://localhost:12345;
|
||||
// tls://localhost:587;10.10.10.10:54321;localhost:12345;10.10.10.10'. $_REQUEST['mail_host'].' ';
|
||||
// self::assertFalse($this->Mail->smtpConnect());
|
||||
// $this->Mail->smtpClose();
|
||||
//All these hosts are expected to fail
|
||||
//$this->Mail->Host = 'xyz://bogus:25;tls://[bogus]:25;ssl://localhost:12345;
|
||||
//tls://localhost:587;10.10.10.10:54321;localhost:12345;10.10.10.10'. $_REQUEST['mail_host'].' ';
|
||||
//self::assertFalse($this->Mail->smtpConnect());
|
||||
//$this->Mail->smtpClose();
|
||||
|
||||
$this->Mail->Host = ' localhost:12345 ; ' . $_REQUEST['mail_host'] . ' ';
|
||||
self::assertTrue($this->Mail->smtpConnect(), 'SMTP hosts with stray spaces failed');
|
||||
$this->Mail->smtpClose();
|
||||
|
||||
// Need to pick a harmless option so as not cause problems of its own! socket:bind doesn't work with Travis-CI
|
||||
//Need to pick a harmless option so as not cause problems of its own! socket:bind doesn't work with Travis-CI
|
||||
$this->Mail->Host = $_REQUEST['mail_host'];
|
||||
self::assertTrue($this->Mail->smtpConnect(['ssl' => ['verify_depth' => 10]]));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user