Skip to content

Commit

Permalink
Release v1.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
getcompass-opensource committed Mar 21, 2024
1 parent da2a482 commit 157ccfc
Showing 1 changed file with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
*/
class Type_Mail_Sender_PhpMailer extends Type_Mail_Sender_AbstractProvider {

public const ENCRYPTION_TLS = "tls";
public const ENCRYPTION_SSL = "ssl";
public const ENCRYPTION_NONE = "";
public const ENCRYPTION_TLS = "tls";
public const ENCRYPTION_SSL = "ssl";

/** @var int уровень дебага */
protected int $_debug_level = SMTP::DEBUG_OFF;
Expand All @@ -30,20 +31,33 @@ class Type_Mail_Sender_PhpMailer extends Type_Mail_Sender_AbstractProvider {
*/
public function __construct(string $host, int $port, string $encryption, string $username, string $password, string $from_address, string $from_name) {

if (!in_array($encryption, [self::ENCRYPTION_TLS, self::ENCRYPTION_SSL])) {
if (!in_array($encryption, [self::ENCRYPTION_NONE, self::ENCRYPTION_TLS, self::ENCRYPTION_SSL])) {
throw new ParseFatalException("passed incorrect encryption [$encryption] parameter");
}

$mailer = new PHPMailer(true);
$mailer->SMTPDebug = $this->_debug_level;
$mailer->isSMTP();
$mailer->CharSet = self::_CHARSET;
$mailer->Host = $host;
$mailer->SMTPAuth = true;
$mailer->Username = $username;
$mailer->Password = $password;
$mailer->SMTPSecure = $encryption;
$mailer->Port = $port;
$mailer->CharSet = self::_CHARSET;
$mailer->Host = $host;

// значение по умолчанию
$mailer->SMTPAuth = false;

// если передали данные для аутентификации
if (mb_strlen($username) > 0 || mb_strlen($password) > 0) {

$mailer->SMTPAuth = true;
$mailer->Username = $username;
$mailer->Password = $password;
}

// если передан тип шифрования
if ($encryption !== self::ENCRYPTION_NONE) {
$mailer->SMTPSecure = $encryption;
}

$mailer->Port = $port;
$mailer->setFrom($from_address, $from_name);
$mailer->isHTML(true);

Expand Down

0 comments on commit 157ccfc

Please sign in to comment.