Skip to content

Commit

Permalink
Use constants more consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
Synchro committed Sep 24, 2019
1 parent ed90156 commit 8414097
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ try {
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user@example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption, `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mail->Port = 587; // TCP port to connect to

//Recipients
Expand Down
4 changes: 2 additions & 2 deletions examples/gmail.phps
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ $mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Set the encryption mechanism to use - STARTTLS or SMTPS
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;

//Whether to use SMTP authentication
$mail->SMTPAuth = true;
Expand Down
6 changes: 3 additions & 3 deletions examples/gmail_xoauth.phps
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ $mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Set the encryption mechanism to use - STARTTLS or SMTPS
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;

//Whether to use SMTP authentication
$mail->SMTPAuth = true;
Expand Down Expand Up @@ -88,7 +88,7 @@ $mail->Subject = 'PHPMailer GMail XOAUTH2 SMTP test';

//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->CharSet = 'utf-8';
$mail->CharSet = PHPMailer::CHARSET_UTF8;
$mail->msgHTML(file_get_contents('contentsutf8.html'), __DIR__);

//Replace the plain text body with one created manually
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_contact_form.phps
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ if (array_key_exists('to', $_POST)) {
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->Port = 2500;
$mail->CharSet = 'utf-8';
$mail->Port = 25;
$mail->CharSet = PHPMailer::CHARSET_UTF8;
//It's important not to use the submitter's address as the from address as it's forgery,
//which will cause your messages to fail SPF checks.
//Use an address in your own domain as the from address, put the submitter's address in a reply-to
Expand Down
4 changes: 2 additions & 2 deletions examples/ssl_options.phps
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ $mail->Host = 'smtp.example.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Set the encryption mechanism to use - STARTTLS or SMTPS
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;

//Custom connection options
//Note that these settings are INSECURE
Expand Down
16 changes: 8 additions & 8 deletions src/PHPMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class PHPMailer

/**
* What kind of encryption to use on the SMTP connection.
* Options: '', 'ssl' or 'tls'.
* Options: '', static::ENCRYPTION_STARTTLS, or static::ENCRYPTION_SMTPS.
*
* @var string
*/
Expand Down Expand Up @@ -1928,19 +1928,19 @@ public function smtpConnect($options = null)
}
$prefix = '';
$secure = $this->SMTPSecure;
$tls = ('tls' == $this->SMTPSecure);
if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) {
$tls = (static::ENCRYPTION_STARTTLS == $this->SMTPSecure);
if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and static::ENCRYPTION_SMTPS == $this->SMTPSecure)) {
$prefix = 'ssl://';
$tls = false; // Can't have SSL and TLS at the same time
$secure = 'ssl';
$secure = static::ENCRYPTION_SMTPS;
} elseif ('tls' == $hostinfo[2]) {
$tls = true;
// tls doesn't use a prefix
$secure = 'tls';
$secure = static::ENCRYPTION_STARTTLS;
}
//Do we need the OpenSSL extension?
$sslext = defined('OPENSSL_ALGO_SHA256');
if ('tls' === $secure or 'ssl' === $secure) {
if (static::ENCRYPTION_STARTTLS === $secure or static::ENCRYPTION_SMTPS === $secure) {
//Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
if (!$sslext) {
throw new Exception($this->lang('extension_missing') . 'openssl', self::STOP_CRITICAL);
Expand Down Expand Up @@ -4189,9 +4189,9 @@ public static function mb_pathinfo($path, $options = null)
* You should avoid this function - it's more verbose, less efficient, more error-prone and
* harder to debug than setting properties directly.
* Usage Example:
* `$mail->set('SMTPSecure', 'tls');`
* `$mail->set('SMTPSecure', static::ENCRYPTION_STARTTLS);`
* is the same as:
* `$mail->SMTPSecure = 'tls';`.
* `$mail->SMTPSecure = static::ENCRYPTION_STARTTLS;`.
*
* @param string $name The property name to set
* @param mixed $value The value to set the property to
Expand Down
18 changes: 9 additions & 9 deletions test/PHPMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function setUp()
$this->Mail->Debugoutput = ['PHPMailer\Test\DebugLogTestListener', 'debugLog'];
$this->Mail->Priority = 3;
$this->Mail->Encoding = '8bit';
$this->Mail->CharSet = 'iso-8859-1';
$this->Mail->CharSet = PHPMailer::CHARSET_ISO88591;
if (array_key_exists('mail_from', $_REQUEST)) {
$this->Mail->From = $_REQUEST['mail_from'];
} else {
Expand Down Expand Up @@ -221,10 +221,10 @@ private function checkChanges()
if (3 != $this->Mail->Priority) {
$this->addChange('Priority', $this->Mail->Priority);
}
if ('8bit' != $this->Mail->Encoding) {
if (PHPMailer::ENCODING_8BIT != $this->Mail->Encoding) {
$this->addChange('Encoding', $this->Mail->Encoding);
}
if ('iso-8859-1' != $this->Mail->CharSet) {
if (PHPMailer::CHARSET_ISO88591 != $this->Mail->CharSet) {
$this->addChange('CharSet', $this->Mail->CharSet);
}
if ('' != $this->Mail->Sender) {
Expand Down Expand Up @@ -312,7 +312,7 @@ public function testAuthCRAMMD5()
$this->Mail->Host = 'hostname';
$this->Mail->Port = 587;
$this->Mail->SMTPAuth = true;
$this->Mail->SMTPSecure = 'tls';
$this->Mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$this->Mail->AuthType = 'CRAM-MD5';
$this->Mail->Username = 'username';
$this->Mail->Password = 'password';
Expand Down Expand Up @@ -1023,7 +1023,7 @@ public function testHtmlIso8859()
{
$this->Mail->isHTML(true);
$this->Mail->Subject .= ': ISO-8859-1 HTML';
$this->Mail->CharSet = 'iso-8859-1';
$this->Mail->CharSet = PHPMailer::CHARSET_ISO88591;

//This file is in ISO-8859-1 charset
//Needs to be external because this file is in UTF-8
Expand Down Expand Up @@ -1135,7 +1135,7 @@ public function testPlainUtf8()
public function testMsgHTML()
{
$message = file_get_contents(realpath($this->INCLUDE_DIR . '/examples/contentsutf8.html'));
$this->Mail->CharSet = 'utf-8';
$this->Mail->CharSet = PHPMailer::CHARSET_UTF8;
$this->Mail->Body = '';
$this->Mail->AltBody = '';
//Uses internal HTML to text conversion
Expand Down Expand Up @@ -1795,7 +1795,7 @@ public function testBCCAddressing()
*/
public function testEncodings()
{
$this->Mail->CharSet = 'iso-8859-1';
$this->Mail->CharSet = PHPMailer::CHARSET_ISO88591;
$this->assertEquals(
'=A1Hola!_Se=F1or!',
$this->Mail->encodeQ("\xa1Hola! Se\xf1or!", 'text'),
Expand Down Expand Up @@ -2432,7 +2432,7 @@ public function testCustomHeaderGetter()
*/
public function testConfirmReadingTo()
{
$this->Mail->CharSet = 'utf-8';
$this->Mail->CharSet = PHPMailer::CHARSET_UTF8;
$this->buildBody();

$this->Mail->ConfirmReadingTo = 'test@example..com'; //Invalid address
Expand Down Expand Up @@ -2522,7 +2522,7 @@ public function testDuplicateIDNRemoved()
$this->Mail->clearAllRecipients();
$this->Mail->clearReplyTos();

$this->Mail->CharSet = 'utf-8';
$this->Mail->CharSet = PHPMailer::CHARSET_UTF8;

$this->assertTrue($this->Mail->addAddress('test@françois.ch'));
$this->assertFalse($this->Mail->addAddress('test@françois.ch'));
Expand Down

0 comments on commit 8414097

Please sign in to comment.