diff --git a/examples/code_generator.phps b/examples/code_generator.phps
index 2aa773f9..2d998e20 100644
--- a/examples/code_generator.phps
+++ b/examples/code_generator.phps
@@ -36,12 +36,12 @@ $authenticate_username = (isset($_POST['authenticate_username'])) ?
$_POST['authenticate_username'] : $CFG['smtp_username'];
// storing all status output from the script to be shown to the user later
-$results_messages = array();
+$results_messages = [];
// $example_code represents the "final code" that we're using, and will
// be shown to the user at the end.
$example_code = "\nrequire_once '../PHPMailerAutoload.php';";
-$example_code .= "\n\n\$results_messages = array();";
+$example_code .= "\n\n\$results_messages = [];";
$mail = new PHPMailer(true); //PHPMailer instance with exceptions enabled
$mail->CharSet = 'utf-8';
diff --git a/examples/ssl_options.phps b/examples/ssl_options.phps
index 9f025fa8..b6ed4dcf 100644
--- a/examples/ssl_options.phps
+++ b/examples/ssl_options.phps
@@ -36,13 +36,13 @@ $mail->SMTPSecure = 'tls';
//Custom connection options
$mail->SMTPOptions = array (
- 'ssl' => array(
+ 'ssl' => [
'verify_peer' => true,
'verify_depth' => 3,
'allow_self_signed' => true,
'peer_name' => 'smtp.example.com',
'cafile' => '/etc/ssl/ca_cert.pem',
- )
+ ]
);
//Whether to use SMTP authentication
diff --git a/get_oauth_token.php b/get_oauth_token.php
index d77ff040..f0690cff 100644
--- a/get_oauth_token.php
+++ b/get_oauth_token.php
@@ -27,7 +27,6 @@
* * Set the script address as the app's redirect URL
* If no refresh token is obtained when running this file,
* revoke access to your app and run the script again.
- * PHP Version 5.4
*/
if (!isset($_GET['code']) && !isset($_GET['provider'])) {
@@ -95,6 +94,12 @@ if (!isset($_GET['code'])) {
// Use this to interact with an API on the users behalf
echo 'Token: ' . $token->getToken() . '
';
+ $token = $provider->getAccessToken(
+ 'authorization_code',
+ [
+ 'code' => $_GET['code']
+ ]
+ );
// Use this to get a new access token if the old one expires
echo 'Refresh Token: ' . $token->getRefreshToken() . '
';
diff --git a/src/PHPMailer.php b/src/PHPMailer.php
index c018f3f2..0d0814b5 100644
--- a/src/PHPMailer.php
+++ b/src/PHPMailer.php
@@ -254,7 +254,7 @@ class PHPMailer
* Options array passed to stream_context_create when connecting via SMTP.
* @var array
*/
- public $SMTPOptions = array();
+ public $SMTPOptions = [];
/**
* SMTP username.
@@ -346,7 +346,7 @@ class PHPMailer
* @var array
* @TODO This should really not be public
*/
- public $SingleToArray = array();
+ public $SingleToArray = [];
/**
* Whether to generate VERP addresses on send.
@@ -443,28 +443,28 @@ class PHPMailer
* @var array
* @access protected
*/
- protected $to = array();
+ protected $to = [];
/**
* The array of 'cc' names and addresses.
* @var array
* @access protected
*/
- protected $cc = array();
+ protected $cc = [];
/**
* The array of 'bcc' names and addresses.
* @var array
* @access protected
*/
- protected $bcc = array();
+ protected $bcc = [];
/**
* The array of reply-to names and addresses.
* @var array
* @access protected
*/
- protected $ReplyTo = array();
+ protected $ReplyTo = [];
/**
* An array of all kinds of addresses.
@@ -473,7 +473,7 @@ class PHPMailer
* @access protected
* @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
*/
- protected $all_recipients = array();
+ protected $all_recipients = [];
/**
* An array of names and addresses queued for validation.
@@ -485,7 +485,7 @@ class PHPMailer
* @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
* @see PHPMailer::$all_recipients
*/
- protected $RecipientsQueue = array();
+ protected $RecipientsQueue = [];
/**
* An array of reply-to names and addresses queued for validation.
@@ -495,21 +495,21 @@ class PHPMailer
* @access protected
* @see PHPMailer::$ReplyTo
*/
- protected $ReplyToQueue = array();
+ protected $ReplyToQueue = [];
/**
* The array of attachments.
* @var array
* @access protected
*/
- protected $attachment = array();
+ protected $attachment = [];
/**
* The array of custom headers.
* @var array
* @access protected
*/
- protected $CustomHeader = array();
+ protected $CustomHeader = [];
/**
* The most recent Message-ID (including angular brackets).
@@ -530,14 +530,14 @@ class PHPMailer
* @var array
* @access protected
*/
- protected $boundary = array();
+ protected $boundary = [];
/**
* The array of available languages.
* @var array
* @access protected
*/
- protected $language = array();
+ protected $language = [];
/**
* The number of errors encountered.
@@ -682,7 +682,7 @@ class PHPMailer
return;
}
//Avoid clash with built-in function names
- if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
+ if (!in_array($this->Debugoutput, ['error_log', 'html', 'echo']) and is_callable($this->Debugoutput)) {
call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
return;
}
@@ -848,7 +848,7 @@ class PHPMailer
}
return false;
}
- $params = array($kind, $address, $name);
+ $params = [$kind, $address, $name];
// Enqueue addresses with IDN until we know the PHPMailer::$CharSet.
if ($this->has8bitChars(substr($address, ++$pos)) and $this->idnSupported()) {
if ($kind != 'Reply-To') {
@@ -865,7 +865,7 @@ class PHPMailer
return false;
}
// Immediately add standard addresses without IDN.
- return call_user_func_array(array($this, 'addAnAddress'), $params);
+ return call_user_func_array([$this, 'addAnAddress'], $params);
}
/**
@@ -880,7 +880,7 @@ class PHPMailer
*/
protected function addAnAddress($kind, $address, $name = '')
{
- if (!in_array($kind, array('to', 'cc', 'bcc', 'Reply-To'))) {
+ if (!in_array($kind, ['to', 'cc', 'bcc', 'Reply-To'])) {
$error_message = $this->lang('Invalid recipient kind: ') . $kind;
$this->setError($error_message);
$this->edebug($error_message);
@@ -900,13 +900,13 @@ class PHPMailer
}
if ($kind != 'Reply-To') {
if (!array_key_exists(strtolower($address), $this->all_recipients)) {
- array_push($this->$kind, array($address, $name));
+ array_push($this->$kind, [$address, $name]);
$this->all_recipients[strtolower($address)] = true;
return true;
}
} else {
if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
- $this->ReplyTo[strtolower($address)] = array($address, $name);
+ $this->ReplyTo[strtolower($address)] = [$address, $name];
return true;
}
}
@@ -925,17 +925,17 @@ class PHPMailer
*/
public function parseAddresses($addrstr, $useimap = true)
{
- $addresses = array();
+ $addresses = [];
if ($useimap and function_exists('imap_rfc822_parse_adrlist')) {
//Use this built-in parser if it's available
$list = imap_rfc822_parse_adrlist($addrstr, '');
foreach ($list as $address) {
if ($address->host != '.SYNTAX-ERROR.') {
if ($this->validateAddress($address->mailbox . '@' . $address->host)) {
- $addresses[] = array(
+ $addresses[] = [
'name' => (property_exists($address, 'personal') ? $address->personal : ''),
'address' => $address->mailbox . '@' . $address->host
- );
+ ];
}
}
}
@@ -948,19 +948,19 @@ class PHPMailer
if (strpos($address, '<') === false) {
//No separate name, just use the whole thing
if ($this->validateAddress($address)) {
- $addresses[] = array(
+ $addresses[] = [
'name' => '',
'address' => $address
- );
+ ];
}
} else {
list($name, $email) = explode('<', $address);
$email = trim(str_replace('>', '', $email));
if ($this->validateAddress($email)) {
- $addresses[] = array(
- 'name' => trim(str_replace(array('"', "'"), '', $name)),
+ $addresses[] = [
+ 'name' => trim(str_replace(['"', "'"], '', $name)),
'address' => $email
- );
+ ];
}
}
}
@@ -1185,14 +1185,14 @@ class PHPMailer
// 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(array($this, 'addAnAddress'), $params);
+ call_user_func_array([$this, 'addAnAddress'], $params);
}
if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
throw new Exception($this->lang('provide_address'), self::STOP_CRITICAL);
}
// Validate From, Sender, and ConfirmReadingTo addresses
- foreach (array('From', 'Sender', 'ConfirmReadingTo') as $address_kind) {
+ foreach (['From', 'Sender', 'ConfirmReadingTo'] as $address_kind) {
$this->$address_kind = trim($this->$address_kind);
if (empty($this->$address_kind)) {
continue;
@@ -1336,7 +1336,7 @@ class PHPMailer
$result = pclose($mail);
$this->doCallback(
($result == 0),
- array($toAddr),
+ [$toAddr],
$this->cc,
$this->bcc,
$this->Subject,
@@ -1381,7 +1381,7 @@ class PHPMailer
*/
protected function mailSend($header, $body)
{
- $toArr = array();
+ $toArr = [];
foreach ($this->to as $toaddr) {
$toArr[] = $this->addrFormat($toaddr);
}
@@ -1400,7 +1400,7 @@ class PHPMailer
if ($this->SingleTo && count($toArr) > 1) {
foreach ($toArr as $toAddr) {
$result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
- $this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
+ $this->doCallback($result, [$toAddr], $this->cc, $this->bcc, $this->Subject, $body, $this->From);
}
} else {
$result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
@@ -1442,7 +1442,7 @@ class PHPMailer
*/
protected function smtpSend($header, $body)
{
- $bad_rcpt = array();
+ $bad_rcpt = [];
if (!$this->smtpConnect($this->SMTPOptions)) {
throw new Exception($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
}
@@ -1457,16 +1457,16 @@ class PHPMailer
}
// Attempt to send to all recipients
- foreach (array($this->to, $this->cc, $this->bcc) as $togroup) {
+ foreach ([$this->to, $this->cc, $this->bcc] as $togroup) {
foreach ($togroup as $to) {
if (!$this->smtp->recipient($to[0])) {
$error = $this->smtp->getError();
- $bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']);
+ $bad_rcpt[] = ['to' => $to[0], 'error' => $error['detail']];
$isSent = false;
} else {
$isSent = true;
}
- $this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
+ $this->doCallback($isSent, [$to[0]], [], [], $this->Subject, $body, $this->From);
}
}
@@ -1504,7 +1504,7 @@ class PHPMailer
* @uses SMTP
* @access public
*/
- public function smtpConnect($options = array())
+ public function smtpConnect($options = [])
{
if (is_null($this->smtp)) {
$this->smtp = $this->getSMTPInstance();
@@ -1523,7 +1523,7 @@ class PHPMailer
$lastexception = null;
foreach ($hosts as $hostentry) {
- $hostinfo = array();
+ $hostinfo = [];
if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
// Not a valid host entry
continue;
@@ -1638,7 +1638,7 @@ class PHPMailer
public function setLanguage($langcode = 'en', $lang_path = '')
{
// Define full set of translatable strings in English
- $PHPMAILER_LANG = array(
+ $PHPMAILER_LANG = [
'authenticate' => 'SMTP Error: Could not authenticate.',
'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
'data_not_accepted' => 'SMTP Error: data not accepted.',
@@ -1658,7 +1658,7 @@ class PHPMailer
'smtp_error' => 'SMTP server error: ',
'variable_set' => 'Cannot set or reset variable: ',
'extension_missing' => 'Extension missing: '
- );
+ ];
if (empty($lang_path)) {
// Calculate an absolute path so it can work if CWD is not here
$lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
@@ -1696,12 +1696,12 @@ class PHPMailer
* @param array $addr An array of recipient,
* where each recipient is a 2-element indexed array with element 0 containing an address
* and element 1 containing a name, like:
- * array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User'))
+ * [['joe@example.com', 'Joe User'], ['zoe@example.com', 'Zoe User']]
* @return string
*/
public function addrAppend($type, $addr)
{
- $addresses = array();
+ $addresses = [];
foreach ($addr as $address) {
$addresses[] = $this->addrFormat($address);
}
@@ -1712,7 +1712,7 @@ class PHPMailer
* Format an address for use in a message header.
* @access public
* @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name
- * like array('joe@example.com', 'Joe User')
+ * like ['joe@example.com', 'Joe User']
* @return string
*/
public function addrFormat($addr)
@@ -1931,7 +1931,7 @@ class PHPMailer
}
}
- $result .= $this->addrAppend('From', array(array(trim($this->From), $this->FromName)));
+ $result .= $this->addrAppend('From', [[trim($this->From), $this->FromName]]);
// sendmail and mail() extract Cc from the header before sending
if (count($this->cc) > 0) {
@@ -2232,7 +2232,7 @@ class PHPMailer
$file,
$signed,
'file://' . realpath($this->sign_cert_file),
- array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
+ ['file://' . realpath($this->sign_key_file), $this->sign_key_pass],
null
);
} else {
@@ -2240,7 +2240,7 @@ class PHPMailer
$file,
$signed,
'file://' . realpath($this->sign_cert_file),
- array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
+ ['file://' . realpath($this->sign_key_file), $this->sign_key_pass],
null,
PKCS7_DETACHED,
$this->sign_extracerts_file
@@ -2322,7 +2322,7 @@ class PHPMailer
*/
protected function setMessageType()
{
- $type = array();
+ $type = [];
if ($this->alternativeExists()) {
$type[] = 'alt';
}
@@ -2389,7 +2389,7 @@ class PHPMailer
$name = $filename;
}
- $this->attachment[] = array(
+ $this->attachment[] = [
0 => $path,
1 => $filename,
2 => $name,
@@ -2398,7 +2398,7 @@ class PHPMailer
5 => false, // isStringAttachment
6 => $disposition,
7 => 0
- );
+ ];
} catch (Exception $exc) {
$this->setError($exc->getMessage());
@@ -2431,9 +2431,9 @@ class PHPMailer
protected function attachAll($disposition_type, $boundary)
{
// Return text of body
- $mime = array();
- $cidUniq = array();
- $incl = array();
+ $mime = [];
+ $cidUniq = [];
+ $incl = [];
// Add all attachments
foreach ($this->attachment as $attachment) {
@@ -2755,8 +2755,8 @@ class PHPMailer
}
// Fall back to a pure PHP implementation
$string = str_replace(
- array('%20', '%0D%0A.', '%0D%0A', '%'),
- array(' ', "\r\n=2E", "\r\n", '='),
+ ['%20', '%0D%0A.', '%0D%0A', '%'],
+ [' ', "\r\n=2E", "\r\n", '='],
rawurlencode($string)
);
return preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
@@ -2774,7 +2774,7 @@ class PHPMailer
{
// There should not be any EOL in the string
$pattern = '';
- $encoded = str_replace(array("\r", "\n"), '', $str);
+ $encoded = str_replace(["\r", "\n"], '', $str);
switch (strtolower($position)) {
case 'phrase':
// RFC 2047 section 5.3
@@ -2793,7 +2793,7 @@ class PHPMailer
$pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
break;
}
- $matches = array();
+ $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
@@ -2833,7 +2833,7 @@ class PHPMailer
$type = self::filenameToType($filename);
}
// Append to $attachment array
- $this->attachment[] = array(
+ $this->attachment[] = [
0 => $string,
1 => $filename,
2 => basename($filename),
@@ -2842,7 +2842,7 @@ class PHPMailer
5 => true, // isStringAttachment
6 => $disposition,
7 => 0
- );
+ ];
}
/**
@@ -2879,7 +2879,7 @@ class PHPMailer
}
// Append to $attachment array
- $this->attachment[] = array(
+ $this->attachment[] = [
0 => $path,
1 => $filename,
2 => $name,
@@ -2888,7 +2888,7 @@ class PHPMailer
5 => false, // isStringAttachment
6 => $disposition,
7 => $cid
- );
+ ];
return true;
}
@@ -2920,7 +2920,7 @@ class PHPMailer
}
// Append to $attachment array
- $this->attachment[] = array(
+ $this->attachment[] = [
0 => $string,
1 => $name,
2 => $name,
@@ -2929,7 +2929,7 @@ class PHPMailer
5 => true, // isStringAttachment
6 => $disposition,
7 => $cid
- );
+ ];
return true;
}
@@ -2996,7 +2996,7 @@ class PHPMailer
foreach ($this->to as $to) {
unset($this->all_recipients[strtolower($to[0])]);
}
- $this->to = array();
+ $this->to = [];
$this->clearQueuedAddresses('to');
}
@@ -3009,7 +3009,7 @@ class PHPMailer
foreach ($this->cc as $cc) {
unset($this->all_recipients[strtolower($cc[0])]);
}
- $this->cc = array();
+ $this->cc = [];
$this->clearQueuedAddresses('cc');
}
@@ -3022,7 +3022,7 @@ class PHPMailer
foreach ($this->bcc as $bcc) {
unset($this->all_recipients[strtolower($bcc[0])]);
}
- $this->bcc = array();
+ $this->bcc = [];
$this->clearQueuedAddresses('bcc');
}
@@ -3032,8 +3032,8 @@ class PHPMailer
*/
public function clearReplyTos()
{
- $this->ReplyTo = array();
- $this->ReplyToQueue = array();
+ $this->ReplyTo = [];
+ $this->ReplyToQueue = [];
}
/**
@@ -3042,11 +3042,11 @@ class PHPMailer
*/
public function clearAllRecipients()
{
- $this->to = array();
- $this->cc = array();
- $this->bcc = array();
- $this->all_recipients = array();
- $this->RecipientsQueue = array();
+ $this->to = [];
+ $this->cc = [];
+ $this->bcc = [];
+ $this->all_recipients = [];
+ $this->RecipientsQueue = [];
}
/**
@@ -3055,7 +3055,7 @@ class PHPMailer
*/
public function clearAttachments()
{
- $this->attachment = array();
+ $this->attachment = [];
}
/**
@@ -3064,7 +3064,7 @@ class PHPMailer
*/
public function clearCustomHeaders()
{
- $this->CustomHeader = array();
+ $this->CustomHeader = [];
}
/**
@@ -3175,7 +3175,7 @@ class PHPMailer
public function fixEOL($str)
{
// Normalise to \n
- $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
+ $nstr = str_replace(["\r\n", "\r"], "\n", $str);
// Now convert LE as needed
if ($this->LE !== "\n") {
$nstr = str_replace("\n", $this->LE, $nstr);
@@ -3198,7 +3198,7 @@ class PHPMailer
// Value passed in as name:value
$this->CustomHeader[] = explode(':', $name, 2);
} else {
- $this->CustomHeader[] = array($name, $value);
+ $this->CustomHeader[] = [$name, $value];
}
}
@@ -3328,7 +3328,7 @@ class PHPMailer
*/
public static function _mime_types($ext = '')
{
- $mimes = array(
+ $mimes = [
'xl' => 'application/excel',
'js' => 'application/javascript',
'hqx' => 'application/mac-binhex40',
@@ -3427,7 +3427,7 @@ class PHPMailer
'rv' => 'video/vnd.rn-realvideo',
'avi' => 'video/x-msvideo',
'movie' => 'video/x-sgi-movie'
- );
+ ];
if (array_key_exists(strtolower($ext), $mimes)) {
return $mimes[strtolower($ext)];
}
@@ -3465,8 +3465,8 @@ class PHPMailer
*/
public static function mb_pathinfo($path, $options = null)
{
- $ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '');
- $pathinfo = array();
+ $ret = ['dirname' => '', 'basename' => '', 'extension' => '', 'filename' => ''];
+ $pathinfo = [];
if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) {
if (array_key_exists(1, $pathinfo)) {
$ret['dirname'] = $pathinfo[1];
@@ -3532,7 +3532,7 @@ class PHPMailer
*/
public function secureHeader($str)
{
- return trim(str_replace(array("\r", "\n"), '', $str));
+ return trim(str_replace(["\r", "\n"], '', $str));
}
/**
@@ -3807,7 +3807,7 @@ class PHPMailer
protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
{
if (!empty($this->action_function) && is_callable($this->action_function)) {
- $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
+ $params = [$isSent, $to, $cc, $bcc, $subject, $body, $from];
call_user_func_array($this->action_function, $params);
}
}
diff --git a/src/PHPMailerOAuth.php b/src/PHPMailerOAuth.php
index a34ccc87..374bae69 100644
--- a/src/PHPMailerOAuth.php
+++ b/src/PHPMailerOAuth.php
@@ -58,7 +58,7 @@ class PHPMailerOAuth extends PHPMailer
* @uses SMTP
* @access public
*/
- public function smtpConnect($options = array())
+ public function smtpConnect($options = [])
{
if (is_null($this->smtp)) {
$this->smtp = $this->getSMTPInstance();
@@ -81,7 +81,7 @@ class PHPMailerOAuth extends PHPMailer
$lastexception = null;
foreach ($hosts as $hostentry) {
- $hostinfo = array();
+ $hostinfo = [];
if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
// Not a valid host entry
continue;
diff --git a/src/POP3.php b/src/POP3.php
index e7646d08..9039cda4 100644
--- a/src/POP3.php
+++ b/src/POP3.php
@@ -122,7 +122,7 @@ class POP3
* @var array
* @access protected
*/
- protected $errors = array();
+ protected $errors = [];
/**
* Line break constant
@@ -183,7 +183,7 @@ class POP3
$this->username = $username;
$this->password = $password;
// Reset the error log
- $this->errors = array();
+ $this->errors = [];
// connect
$result = $this->connect($this->host, $this->port, $this->tval);
if ($result) {
@@ -215,7 +215,7 @@ class POP3
//On Windows this will raise a PHP Warning error if the hostname doesn't exist.
//Rather than suppress it with @fsockopen, capture it cleanly instead
- set_error_handler(array($this, 'catchWarning'));
+ set_error_handler([$this, 'catchWarning']);
if (false === $port) {
$port = $this->POP3_PORT;
@@ -235,11 +235,13 @@ class POP3
// Did we connect?
if (false === $this->pop_conn) {
// It would appear not...
- $this->setError(array(
+ $this->setError(
+ [
'error' => "Failed to connect to server $host on port $port",
'errno' => $errno,
'errstr' => $errstr
- ));
+ ]
+ );
return false;
}
@@ -350,11 +352,13 @@ class POP3
protected function checkResponse($string)
{
if (substr($string, 0, 3) !== '+OK') {
- $this->setError(array(
+ $this->setError(
+ [
'error' => "Server reported an error: $string",
'errno' => 0,
'errstr' => ''
- ));
+ ]
+ );
return false;
} else {
return true;
@@ -398,12 +402,14 @@ class POP3
*/
protected function catchWarning($errno, $errstr, $errfile, $errline)
{
- $this->setError(array(
- 'error' => "Connecting to the POP3 server raised a PHP warning: ",
+ $this->setError(
+ [
+ 'error' => 'Connecting to the POP3 server raised a PHP warning: ',
'errno' => $errno,
'errstr' => $errstr,
'errfile' => $errfile,
'errline' => $errline
- ));
+ ]
+ );
}
}
diff --git a/src/SMTP.php b/src/SMTP.php
index 2eef7f58..c46710c8 100644
--- a/src/SMTP.php
+++ b/src/SMTP.php
@@ -154,12 +154,12 @@ class SMTP
* Error information, if any, for the last SMTP command.
* @var array
*/
- protected $error = array(
+ protected $error = [
'error' => '',
'detail' => '',
'smtp_code' => '',
'smtp_code_ex' => ''
- );
+ ];
/**
* The reply the server sent to us for HELO.
@@ -199,7 +199,7 @@ class SMTP
return;
}
//Avoid clash with built-in function names
- if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
+ if (!in_array($this->Debugoutput, ['error_log', 'html', 'echo']) and is_callable($this->Debugoutput)) {
call_user_func($this->Debugoutput, $str, $this->do_debug);
return;
}
@@ -238,7 +238,7 @@ class SMTP
* @access public
* @return boolean
*/
- public function connect($host, $port = null, $timeout = 30, $options = array())
+ public function connect($host, $port = null, $timeout = 30, $options = [])
{
static $streamok;
//This is enabled by default since 5.0.0 but some providers disable it
@@ -379,7 +379,7 @@ class SMTP
);
if (empty($authtype)) {
- foreach (array('LOGIN', 'CRAM-MD5', 'NTLM', 'PLAIN', 'XOAUTH2') as $method) {
+ foreach (['LOGIN', 'CRAM-MD5', 'NTLM', 'PLAIN', 'XOAUTH2'] as $method) {
if (in_array($method, $this->server_caps['AUTH'])) {
$authtype = $method;
break;
@@ -567,7 +567,7 @@ class SMTP
*/
// Normalize line breaks before exploding
- $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data));
+ $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
* of the first line (':' separated) does not contain a space then it _should_ be a header and we will
@@ -581,7 +581,7 @@ class SMTP
}
foreach ($lines as $line) {
- $lines_out = array();
+ $lines_out = [];
if ($in_headers and $line == '') {
$in_headers = false;
}
@@ -675,7 +675,7 @@ class SMTP
*/
protected function parseHelloFields($type)
{
- $this->server_caps = array();
+ $this->server_caps = [];
$lines = explode("\n", $this->last_reply);
foreach ($lines as $n => $s) {
@@ -697,7 +697,7 @@ class SMTP
break;
case 'AUTH':
if (!is_array($fields)) {
- $fields = array();
+ $fields = [];
}
break;
default:
@@ -763,7 +763,7 @@ class SMTP
return $this->sendCommand(
'RCPT TO',
'RCPT TO:<' . $address . '>',
- array(250, 251)
+ [250, 251]
);
}
@@ -802,7 +802,7 @@ class SMTP
$this->last_reply = $this->get_lines();
// Fetch SMTP code and possible error code explanation
- $matches = array();
+ $matches = [];
if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) {
$code = $matches[1];
$code_ex = (count($matches) > 2 ? $matches[2] : null);
@@ -865,7 +865,7 @@ class SMTP
*/
public function verify($name)
{
- return $this->sendCommand('VRFY', "VRFY $name", array(250, 251));
+ return $this->sendCommand('VRFY', "VRFY $name", [250, 251]);
}
/**
@@ -1057,12 +1057,12 @@ class SMTP
*/
protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '')
{
- $this->error = array(
+ $this->error = [
'error' => $message,
'detail' => $detail,
'smtp_code' => $smtp_code,
'smtp_code_ex' => $smtp_code_ex
- );
+ ];
}
/**
diff --git a/test/phpmailerLangTest.php b/test/phpmailerLangTest.php
index d3cf2f82..a3de2802 100644
--- a/test/phpmailerLangTest.php
+++ b/test/phpmailerLangTest.php
@@ -56,11 +56,11 @@ class PHPMailerLangTest extends \PHPUnit_Framework_TestCase
if ($fileInfo->isDot()) {
continue;
}
- $matches = array();
+ $matches = [];
//Only look at language files, ignore anything else in there
if (preg_match('/^phpmailer\.lang-([a-z_]{2,})\.php$/', $fileInfo->getFilename(), $matches)) {
$lang = $matches[1]; //Extract language code
- $PHPMAILER_LANG = array(); //Language strings get put in here
+ $PHPMAILER_LANG = []; //Language strings get put in here
include $fileInfo->getPathname(); //Get language strings
$missing = array_diff(array_keys($definedStrings), array_keys($PHPMAILER_LANG));
$extra = array_diff(array_keys($PHPMAILER_LANG), array_keys($definedStrings));
diff --git a/test/phpmailerTest.php b/test/phpmailerTest.php
index 129c042a..d38583ff 100644
--- a/test/phpmailerTest.php
+++ b/test/phpmailerTest.php
@@ -12,6 +12,7 @@
*/
namespace PHPMailer\PHPMailer;
+
require '../vendor/autoload.php';
/**
@@ -39,14 +40,14 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
* @private
* @var string[]
*/
- public $ChangeLog = array();
+ public $ChangeLog = [];
/**
* Holds the note log.
* @private
* @var string[]
*/
- public $NoteLog = array();
+ public $NoteLog = [];
/**
* Default include path
@@ -59,7 +60,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
* @var array
* @access private
*/
- private $pids = array();
+ private $pids = [];
/**
* Run before each test is started.
@@ -121,8 +122,8 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
{
// Clean global variables
$this->Mail = null;
- $this->ChangeLog = array();
- $this->NoteLog = array();
+ $this->ChangeLog = [];
+ $this->NoteLog = [];
foreach ($this->pids as $pid) {
$p = escapeshellarg($pid);
@@ -161,7 +162,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
$ReportBody .= '---------------------' . $eol;
$ReportBody .= 'Unit Test Information' . $eol;
$ReportBody .= '---------------------' . $eol;
- $ReportBody .= 'phpmailer version: ' . $this->Mail->Version . $eol;
+ $ReportBody .= 'phpmailer version: ' . PHPMailer::VERSION . $eol;
$ReportBody .= 'Content Type: ' . $this->Mail->ContentType . $eol;
$ReportBody .= 'CharSet: ' . $this->Mail->CharSet . $eol;
@@ -256,7 +257,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
*/
public function addChange($sName, $sNewValue)
{
- $this->ChangeLog[] = array($sName, $sNewValue);
+ $this->ChangeLog[] = [$sName, $sNewValue];
}
/**
@@ -332,7 +333,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
*/
public function testValidate()
{
- $validaddresses = array(
+ $validaddresses = [
'first@iana.org',
'first.last@iana.org',
'1234567890123456789012345678901234567890123456789012345678901234@iana.org',
@@ -465,8 +466,8 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
'test@test.com',
'test@xn--example.com',
'test@example.com'
- );
- $invalidaddresses = array(
+ ];
+ $invalidaddresses = [
'first.last@sub.do,com',
'first\@last@iana.org',
'123456789012345678901234567890123456789012345678901234567890' .
@@ -608,25 +609,25 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
//This is valid RCC5322, but we don't want to allow it
"(\r\n RCPT TO:websec02@d.mbsd.jp\r\n DATA \\\nSubject: spam10\\\n\r\n".
" Hello,\r\n this is a spam mail.\\\n.\r\n QUIT\r\n ) a@gmail.com"
- );
+ ];
// IDNs in Unicode and ASCII forms.
- $unicodeaddresses = array(
+ $unicodeaddresses = [
'first.last@bücher.ch',
'first.last@кто.рф',
'first.last@phplíst.com',
- );
- $asciiaddresses = array(
+ ];
+ $asciiaddresses = [
'first.last@xn--bcher-kva.ch',
'first.last@xn--j1ail.xn--p1ai',
'first.last@xn--phplst-6va.com',
- );
- $goodfails = array();
+ ];
+ $goodfails = [];
foreach (array_merge($validaddresses, $asciiaddresses) as $address) {
if (!PHPMailer::validateAddress($address)) {
$goodfails[] = $address;
}
}
- $badpasses = array();
+ $badpasses = [];
foreach (array_merge($invalidaddresses, $unicodeaddresses) as $address) {
if (PHPMailer::validateAddress($address)) {
$badpasses[] = $address;
@@ -772,7 +773,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
//Check that a quoted printable encode and decode results in the same as went in
$t = file_get_contents(__FILE__); //Use this file as test content
//Force line breaks to UNIX-style
- $t = str_replace(array("\r\n", "\r"), "\n", $t);
+ $t = str_replace(["\r\n", "\r"], "\n", $t);
$this->assertEquals(
$t,
quoted_printable_decode($this->Mail->encodeQP($t)),
@@ -1523,7 +1524,7 @@ EOT;
$this->Mail->Body = 'This message is S/MIME signed.';
$this->buildBody();
- $dn = array(
+ $dn = [
'countryName' => 'UK',
'stateOrProvinceName' => 'Here',
'localityName' => 'There',
@@ -1531,12 +1532,12 @@ EOT;
'organizationalUnitName' => 'PHPMailer',
'commonName' => 'PHPMailer Test',
'emailAddress' => 'phpmailer@example.com'
- );
- $keyconfig = array(
+ ];
+ $keyconfig = [
"digest_alg" => "sha256",
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
- );
+ ];
$password = 'password';
$certfile = 'certfile.txt';
$keyfile = 'keyfile.txt';
@@ -1580,7 +1581,7 @@ EOT;
$this->Mail->Body = 'This message is S/MIME signed with an extra CA cert.';
$this->buildBody();
- $certprops = array(
+ $certprops = [
'countryName' => 'UK',
'stateOrProvinceName' => 'Here',
'localityName' => 'There',
@@ -1588,8 +1589,8 @@ EOT;
'organizationalUnitName' => 'PHPMailer',
'commonName' => 'PHPMailer Test',
'emailAddress' => 'phpmailer@example.com'
- );
- $cacertprops = array(
+ ];
+ $cacertprops = [
'countryName' => 'UK',
'stateOrProvinceName' => 'Here',
'localityName' => 'There',
@@ -1597,12 +1598,12 @@ EOT;
'organizationalUnitName' => 'PHPMailer CA',
'commonName' => 'PHPMailer Test CA',
'emailAddress' => 'phpmailer@example.com'
- );
- $keyconfig = array(
- "digest_alg" => "sha256",
- "private_key_bits" => 2048,
- "private_key_type" => OPENSSL_KEYTYPE_RSA,
- );
+ ];
+ $keyconfig = [
+ 'digest_alg' => 'sha256',
+ 'private_key_bits' => 2048,
+ 'private_key_type' => OPENSSL_KEYTYPE_RSA,
+ ];
$password = 'password';
$cacertfile = 'cacertfile.pem';
$cakeyfile = 'cakeyfile.pem';
@@ -1664,10 +1665,10 @@ EOT;
//(2048 bits is the recommended minimum key length -
//gmail won't accept less than 1024 bits)
$pk = openssl_pkey_new(
- array(
+ [
'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA
- )
+ ]
);
openssl_pkey_export_to_file($pk, $privatekeyfile);
$this->Mail->DKIM_domain = 'example.com';
@@ -1787,25 +1788,31 @@ EOT;
public function testCustomHeaderGetter()
{
$this->Mail->addCustomHeader('foo', 'bar');
- $this->assertEquals(array(array('foo', 'bar')), $this->Mail->getCustomHeaders());
+ $this->assertEquals([['foo', 'bar']], $this->Mail->getCustomHeaders());
$this->Mail->addCustomHeader('foo', 'baz');
- $this->assertEquals(array(
- array('foo', 'bar'),
- array('foo', 'baz')
- ), $this->Mail->getCustomHeaders());
+ $this->assertEquals(
+ [
+ ['foo', 'bar'],
+ ['foo', 'baz']
+ ],
+ $this->Mail->getCustomHeaders()
+ );
$this->Mail->clearCustomHeaders();
$this->assertEmpty($this->Mail->getCustomHeaders());
$this->Mail->addCustomHeader('yux');
- $this->assertEquals(array(array('yux')), $this->Mail->getCustomHeaders());
+ $this->assertEquals([['yux']], $this->Mail->getCustomHeaders());
$this->Mail->addCustomHeader('Content-Type: application/json');
- $this->assertEquals(array(
- array('yux'),
- array('Content-Type', ' application/json')
- ), $this->Mail->getCustomHeaders());
+ $this->assertEquals(
+ [
+ ['yux'],
+ ['Content-Type', ' application/json']
+ ],
+ $this->Mail->getCustomHeaders()
+ );
}
/**
@@ -1872,18 +1879,21 @@ EOT;
// Addresses with IDN are returned by get*Addresses() after send() call.
$domain = $this->Mail->punyencodeAddress($domain);
$this->assertEquals(
- array(array('test' . $domain, '')),
+ [['test' . $domain, '']],
$this->Mail->getToAddresses(),
- 'Bad "to" recipients');
+ 'Bad "to" recipients'
+ );
$this->assertEquals(
- array(array('test+cc' . $domain, '')),
+ [['test+cc' . $domain, '']],
$this->Mail->getCcAddresses(),
- 'Bad "cc" recipients');
+ 'Bad "cc" recipients'
+ );
$this->assertEmpty($this->Mail->getBccAddresses(), 'Bad "bcc" recipients');
$this->assertEquals(
- array('test+replyto' . $domain => array('test+replyto' . $domain, '')),
+ ['test+replyto' . $domain => ['test+replyto' . $domain, '']],
$this->Mail->getReplyToAddresses(),
- 'Bad "reply-to" addresses');
+ 'Bad "reply-to" addresses'
+ );
}
/**
@@ -1981,19 +1991,19 @@ EOT;
$this->Mail->SMTPDebug = 4; //Show connection-level errors
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP single connect failed');
$this->Mail->smtpClose();
- $this->Mail->Host = "ssl://localhost:12345;tls://localhost:587;10.10.10.10:54321;localhost:12345;10.10.10.10";
+ $this->Mail->Host = 'ssl://localhost:12345;tls://localhost:587;10.10.10.10:54321;localhost:12345;10.10.10.10';
$this->assertFalse($this->Mail->smtpConnect(), 'SMTP bad multi-connect succeeded');
$this->Mail->smtpClose();
- $this->Mail->Host = "localhost:12345;10.10.10.10:54321;" . $_REQUEST['mail_host'];
+ $this->Mail->Host = 'localhost:12345;10.10.10.10:54321;' . $_REQUEST['mail_host'];
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP multi-connect failed');
$this->Mail->smtpClose();
- $this->Mail->Host = " localhost:12345 ; " . $_REQUEST['mail_host'] . ' ';
+ $this->Mail->Host = ' localhost:12345 ; ' . $_REQUEST['mail_host'] . ' ';
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP hosts with stray spaces failed');
$this->Mail->smtpClose();
$this->Mail->Host = $_REQUEST['mail_host'];
//Need to pick a harmless option so as not cause problems of its own! socket:bind doesn't work with Travis-CI
$this->assertTrue(
- $this->Mail->smtpConnect(array('ssl' => array('verify_depth' => 10))),
+ $this->Mail->smtpConnect(['ssl' => ['verify_depth' => 10]]),
'SMTP connect with options failed'
);
}