diff --git a/examples/extending.phps b/examples/extending.phps index e7b2d880..c04a731d 100644 --- a/examples/extending.phps +++ b/examples/extending.phps @@ -9,6 +9,7 @@ //Import PHPMailer classes into the global namespace use PHPMailer\PHPMailer\PHPMailer; +use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; require '../vendor/autoload.php'; @@ -37,7 +38,7 @@ class myPHPMailer extends PHPMailer //Set an HTML and plain-text body, import relative image references $this->msgHTML($body, './images/'); //Show debug output - $this->SMTPDebug = 2; + $this->SMTPDebug = SMTP::DEBUG_SERVER; //Inject a new debug output handler $this->Debugoutput = function ($str, $level) { echo "Debug level $level; message: $str\n"; diff --git a/examples/gmail.phps b/examples/gmail.phps index f2c1afc3..1dfb5a93 100644 --- a/examples/gmail.phps +++ b/examples/gmail.phps @@ -8,6 +8,7 @@ //Import PHPMailer classes into the global namespace use PHPMailer\PHPMailer\PHPMailer; +use PHPMailer\PHPMailer\SMTP; require '../vendor/autoload.php'; @@ -18,10 +19,10 @@ $mail = new PHPMailer; $mail->isSMTP(); //Enable SMTP debugging -// 0 = off (for production use) -// 1 = client messages -// 2 = client and server messages -$mail->SMTPDebug = 2; +// 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'; diff --git a/examples/gmail_xoauth.phps b/examples/gmail_xoauth.phps index be2de7e6..0288cbc4 100644 --- a/examples/gmail_xoauth.phps +++ b/examples/gmail_xoauth.phps @@ -5,6 +5,7 @@ //Import PHPMailer classes into the global namespace use PHPMailer\PHPMailer\PHPMailer; +use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\OAuth; // Alias the League Google OAuth2 provider class @@ -25,10 +26,10 @@ $mail = new PHPMailer; $mail->isSMTP(); //Enable SMTP debugging -// 0 = off (for production use) -// 1 = client messages -// 2 = client and server messages -$mail->SMTPDebug = 2; +// 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'; diff --git a/examples/pop_before_smtp.phps b/examples/pop_before_smtp.phps index 94222d81..31d7876a 100644 --- a/examples/pop_before_smtp.phps +++ b/examples/pop_before_smtp.phps @@ -8,6 +8,7 @@ use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\POP3; +use PHPMailer\PHPMailer\SMTP; require '../vendor/autoload.php'; @@ -22,10 +23,10 @@ $mail = new PHPMailer(true); try { $mail->isSMTP(); //Enable SMTP debugging - // 0 = off (for production use) - // 1 = client messages - // 2 = client and server messages - $mail->SMTPDebug = 2; + // 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'; //Set the SMTP port number - likely to be 25, 465 or 587 diff --git a/examples/smtp.phps b/examples/smtp.phps index 792d8d9c..97a42d3a 100644 --- a/examples/smtp.phps +++ b/examples/smtp.phps @@ -5,6 +5,7 @@ //Import the PHPMailer class into the global namespace use PHPMailer\PHPMailer\PHPMailer; +use PHPMailer\PHPMailer\SMTP; //SMTP needs accurate times, and the PHP time zone MUST be set //This should be done in your php.ini, but this is how to do it if you don't have access to that @@ -17,10 +18,10 @@ $mail = new PHPMailer; //Tell PHPMailer to use SMTP $mail->isSMTP(); //Enable SMTP debugging -// 0 = off (for production use) -// 1 = client messages -// 2 = client and server messages -$mail->SMTPDebug = 2; +// 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'; //Set the SMTP port number - likely to be 25, 465 or 587 diff --git a/examples/smtp_no_auth.phps b/examples/smtp_no_auth.phps index c635434e..6b3fc7d1 100644 --- a/examples/smtp_no_auth.phps +++ b/examples/smtp_no_auth.phps @@ -5,6 +5,7 @@ //Import the PHPMailer class into the global namespace use PHPMailer\PHPMailer\PHPMailer; +use PHPMailer\PHPMailer\SMTP; //SMTP needs accurate times, and the PHP time zone MUST be set //This should be done in your php.ini, but this is how to do it if you don't have access to that @@ -17,10 +18,10 @@ $mail = new PHPMailer; //Tell PHPMailer to use SMTP $mail->isSMTP(); //Enable SMTP debugging -// 0 = off (for production use) -// 1 = client messages -// 2 = client and server messages -$mail->SMTPDebug = 2; +// 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'; //Set the SMTP port number - likely to be 25, 465 or 587 diff --git a/examples/ssl_options.phps b/examples/ssl_options.phps index 674079b6..6c697155 100644 --- a/examples/ssl_options.phps +++ b/examples/ssl_options.phps @@ -5,6 +5,7 @@ //Import the PHPMailer class into the global namespace use PHPMailer\PHPMailer\PHPMailer; +use PHPMailer\PHPMailer\SMTP; //SMTP needs accurate times, and the PHP time zone MUST be set //This should be done in your php.ini, but this is how to do it if you don't have access to that @@ -19,10 +20,10 @@ $mail = new PHPMailer; $mail->isSMTP(); //Enable SMTP debugging -// 0 = off (for production use) -// 1 = client messages -// 2 = client and server messages -$mail->SMTPDebug = 2; +// 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.example.com'; diff --git a/src/PHPMailer.php b/src/PHPMailer.php index 978e00ee..367daf7e 100644 --- a/src/PHPMailer.php +++ b/src/PHPMailer.php @@ -3,7 +3,7 @@ * PHPMailer - PHP email creation and transport class. * PHP Version 5.5. * - * @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project + * @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project * * @author Marcus Bointon (Synchro/coolbru) * @author Jim Jagielski (jimjag) @@ -23,10 +23,10 @@ namespace PHPMailer\PHPMailer; /** * PHPMailer - PHP email creation and transport class. * - * @author Marcus Bointon (Synchro/coolbru) - * @author Jim Jagielski (jimjag) - * @author Andy Prevost (codeworxtech) - * @author Brent R. Matzelle (original founder) + * @author Marcus Bointon (Synchro/coolbru) + * @author Jim Jagielski (jimjag) + * @author Andy Prevost (codeworxtech) + * @author Brent R. Matzelle (original founder) */ class PHPMailer { @@ -388,11 +388,11 @@ class PHPMailer * SMTP class debug output mode. * Debug output level. * Options: - * * `0` No output - * * `1` Commands - * * `2` Data and commands - * * `3` As 2 plus connection status - * * `4` Low-level data output. + * * SMTP::DEBUG_OFF: No output + * * SMTP::DEBUG_CLIENT: Client messages + * * SMTP::DEBUG_SERVER: Client and server messages + * * SMTP::DEBUG_CONNECTION: As SERVER plus connection status + * * SMTP::DEBUG_LOWLEVEL: Noisy, low-level data output, rarely needed * * @see SMTP::$do_debug * @@ -1109,9 +1109,11 @@ class PHPMailer protected function addAnAddress($kind, $address, $name = '') { if (!in_array($kind, ['to', 'cc', 'bcc', 'Reply-To'])) { - $error_message = sprintf('%s: %s', + $error_message = sprintf( + '%s: %s', $this->lang('Invalid recipient kind'), - $kind); + $kind + ); $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) { @@ -1121,10 +1123,12 @@ class PHPMailer return false; } if (!static::validateAddress($address)) { - $error_message = sprintf('%s (%s): %s', + $error_message = sprintf( + '%s (%s): %s', $this->lang('invalid_address'), $kind, - $address); + $address + ); $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) { @@ -1157,7 +1161,7 @@ class PHPMailer * Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available. * Note that quotes in the name part are removed. * - * @see http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php A more careful implementation + * @see http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php A more careful implementation * * @param string $addrstr The address list string * @param bool $useimap Whether to use the IMAP extension to parse the list @@ -1227,12 +1231,15 @@ class PHPMailer $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim // Don't validate now addresses with IDN. Will be done in send(). $pos = strrpos($address, '@'); - if (false === $pos or - (!$this->has8bitChars(substr($address, ++$pos)) or !static::idnSupported()) and - !static::validateAddress($address)) { - $error_message = sprintf('%s (From): %s', + if (false === $pos + or (!$this->has8bitChars(substr($address, ++$pos)) or !static::idnSupported()) + and !static::validateAddress($address) + ) { + $error_message = sprintf( + '%s (From): %s', $this->lang('invalid_address'), - $address); + $address + ); $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) { @@ -1368,7 +1375,7 @@ class PHPMailer * - Conversion to punycode is impossible (e.g. required PHP functions are not available) * or fails for any reason (e.g. domain contains characters not allowed in an IDN). * - * @see PHPMailer::$CharSet + * @see PHPMailer::$CharSet * * @param string $address The email address to convert * @@ -1434,8 +1441,8 @@ class PHPMailer */ public function preSend() { - if ('smtp' == $this->Mailer or - ('mail' == $this->Mailer and stripos(PHP_OS, 'WIN') === 0) + if ('smtp' == $this->Mailer + or ('mail' == $this->Mailer and stripos(PHP_OS, 'WIN') === 0) ) { //SMTP mandates RFC-compliant line endings //and it's also used with mail() on Windows @@ -1482,10 +1489,12 @@ class PHPMailer } $this->$address_kind = $this->punyencodeAddress($this->$address_kind); if (!static::validateAddress($this->$address_kind)) { - $error_message = sprintf('%s (%s): %s', + $error_message = sprintf( + '%s (%s): %s', $this->lang('invalid_address'), $address_kind, - $this->$address_kind); + $this->$address_kind + ); $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) { @@ -1602,7 +1611,7 @@ class PHPMailer /** * Send mail using the $Sendmail program. * - * @see PHPMailer::$Sendmail + * @see PHPMailer::$Sendmail * * @param string $header The message headers * @param string $body The message body @@ -1732,7 +1741,7 @@ class PHPMailer /** * Send mail using the PHP mail() function. * - * @see http://www.php.net/manual/en/book.mail.php + * @see http://www.php.net/manual/en/book.mail.php * * @param string $header The message headers * @param string $body The message body @@ -2178,8 +2187,8 @@ class PHPMailer } return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader( - $addr[0] - ) . '>'; + $addr[0] + ) . '>'; } /** @@ -4198,7 +4207,7 @@ class PHPMailer * Multi-byte-safe pathinfo replacement. * Drop-in replacement for pathinfo(), but multibyte- and cross-platform-safe. * - * @see http://www.php.net/manual/en/function.pathinfo.php#107461 + * @see http://www.php.net/manual/en/function.pathinfo.php#107461 * * @param string $path A filename or path, does not need to exist as a file * @param int|string $options Either a PATHINFO_* constant, @@ -4405,7 +4414,7 @@ class PHPMailer * Uses the 'relaxed' algorithm from RFC6376 section 3.4.2. * Canonicalized headers should *always* use CRLF, regardless of mailer setting. * - * @see https://tools.ietf.org/html/rfc6376#section-3.4.2 + * @see https://tools.ietf.org/html/rfc6376#section-3.4.2 * * @param string $signHeader Header * @@ -4449,7 +4458,7 @@ class PHPMailer * Uses the 'simple' algorithm from RFC6376 section 3.4.3. * Canonicalized bodies should *always* use CRLF, regardless of mailer setting. * - * @see https://tools.ietf.org/html/rfc6376#section-3.4.3 + * @see https://tools.ietf.org/html/rfc6376#section-3.4.3 * * @param string $body Message Body * diff --git a/src/POP3.php b/src/POP3.php index 66cf2730..51de2b32 100644 --- a/src/POP3.php +++ b/src/POP3.php @@ -3,7 +3,7 @@ * PHPMailer POP-Before-SMTP Authentication Class. * PHP Version 5.5. * - * @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project + * @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project * * @author Marcus Bointon (Synchro/coolbru) * @author Jim Jagielski (jimjag) @@ -29,14 +29,14 @@ namespace PHPMailer\PHPMailer; * and then loop through your mail sending script. Providing this process doesn't * take longer than the verification period lasts on your POP3 server, you should be fine. * 3) This is really ancient technology; you should only need to use it to talk to very old systems. - * 4) This POP3 class is deliberately lightweight and incomplete, and implements just + * 4) This POP3 class is deliberately lightweight and incomplete, implementing just * enough to do authentication. * If you want a more complete class there are other POP3 classes for PHP available. * - * @author Richard Davey (original author) - * @author Marcus Bointon (Synchro/coolbru) - * @author Jim Jagielski (jimjag) - * @author Andy Prevost (codeworxtech) + * @author Richard Davey (original author) + * @author Marcus Bointon (Synchro/coolbru) + * @author Jim Jagielski (jimjag) + * @author Andy Prevost (codeworxtech) */ class POP3 { diff --git a/src/SMTP.php b/src/SMTP.php index e0f42de7..71978b36 100644 --- a/src/SMTP.php +++ b/src/SMTP.php @@ -24,8 +24,8 @@ namespace PHPMailer\PHPMailer; * PHPMailer RFC821 SMTP email transport class. * Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server. * - * @author Chris Ryan - * @author Marcus Bointon + * @author Chris Ryan + * @author Marcus Bointon */ class SMTP { @@ -59,26 +59,36 @@ class SMTP /** * Debug level for no output. + * + * @var int */ const DEBUG_OFF = 0; /** * Debug level to show client -> server messages. + * + * @var int */ const DEBUG_CLIENT = 1; /** * Debug level to show client -> server and server -> client messages. + * + * @var int */ const DEBUG_SERVER = 2; /** * Debug level to show connection status, client -> server and server -> client messages. + * + * @var int */ const DEBUG_CONNECTION = 3; /** * Debug level to show all messages. + * + * @var int */ const DEBUG_LOWLEVEL = 4; @@ -745,7 +755,7 @@ class SMTP * * @return bool * - * @see hello() + * @see hello() */ protected function sendHello($hello, $host) { @@ -880,10 +890,10 @@ class SMTP } return $this->sendCommand( - 'RCPT TO', - $rcpt, - [250, 251] - ); + 'RCPT TO', + $rcpt, + [250, 251] + ); } /**