1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
class GLPIMailer extends PHPMailer {
function __construct() {
global $CFG_GLPI;
$this->WordWrap = 80;
$this->CharSet = "utf-8";
$this->SetLanguage("en", Config::getLibraryDir("PHPMailer") . "/language/");
if ($CFG_GLPI['smtp_mode'] != MAIL_MAIL) {
$this->Mailer = "smtp";
$this->Host = $CFG_GLPI['smtp_host'].':'.$CFG_GLPI['smtp_port'];
if ($CFG_GLPI['smtp_username'] != '') {
$this->SMTPAuth = true;
$this->Username = $CFG_GLPI['smtp_username'];
$this->Password = Toolbox::decrypt($CFG_GLPI['smtp_passwd'], GLPIKEY);
}
if ($CFG_GLPI['smtp_mode'] == MAIL_SMTPSSL) {
$this->SMTPSecure = "ssl";
}
if ($CFG_GLPI['smtp_mode'] == MAIL_SMTPTLS) {
$this->SMTPSecure = "tls";
}
if (!$CFG_GLPI['smtp_check_certificate']) {
$this->SMTPOptions = ['ssl' => ['verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true]];
}
if ($CFG_GLPI['smtp_sender'] != '') {
$this->Sender = $CFG_GLPI['smtp_sender'];
}
}
if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) {
$this->SMTPDebug = SMTP::DEBUG_CONNECTION;
$this->Debugoutput = function ($message, $level) {
Toolbox::logInFile(
'mail-debug',
"$level - $message"
);
};
}
}
public static function validateAddress($address, $patternselect = "pcre8") {
$isValid = parent::validateAddress($address, $patternselect);
if (!$isValid && Toolbox::endsWith($address, '@localhost')) {
$isValid = parent::ValidateAddress($address . '.me');
}
return $isValid;
}
public function setLanguage($langcode = 'en', $lang_path = '') {
if ($lang_path == '') {
$local_path = dirname(Config::getLibraryDir('PHPMailer\PHPMailer\PHPMailer')) . '/language/';
if (is_dir($local_path)) {
$lang_path = $local_path;
}
}
parent::setLanguage($langcode, $lang_path);
}
}