X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=phpmailer%2Fphpmailer.php;h=30f10ff815f572f414a331cc848269a8fe68bf01;hb=2fc7356cf43a52ac91fa451f0e8a49f83bccf6df;hp=e9a3c66ea90e869b3a922ccb162d418f9d000710;hpb=0fb7e2c6470b73fe617abc87ca43f14cb9a9987f;p=friendica-addons.git diff --git a/phpmailer/phpmailer.php b/phpmailer/phpmailer.php index e9a3c66e..30f10ff8 100644 --- a/phpmailer/phpmailer.php +++ b/phpmailer/phpmailer.php @@ -11,7 +11,7 @@ use Friendica\App; use Friendica\Core\Hook; use Friendica\DI; use Friendica\Object\EMail\IEmail; -use Friendica\Util\ConfigFileLoader; +use Friendica\Core\Config\Util\ConfigFileLoader; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; @@ -20,12 +20,12 @@ require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'a function phpmailer_install() { Hook::register('load_config' , __FILE__, 'phpmailer_load_config'); - Hook::register('emailer_send_prepare', __FILE__, 'phpmailer_emailer_send_prepare'); + Hook::register('emailer_send_prepare', __FILE__, 'phpmailer_emailer_send_prepare', 5); } function phpmailer_load_config(App $a, ConfigFileLoader $loader) { - $a->getConfigCache()->load($loader->loadAddonConfig('phpmailer')); + $a->getConfigCache()->load($loader->loadAddonConfig('phpmailer'), \Friendica\Core\Config\ValueObject\Cache::SOURCE_STATIC); } /** @@ -37,14 +37,14 @@ function phpmailer_emailer_send_prepare(App $a, IEmail &$email) // Passing `true` enables exceptions $mailer = new PHPMailer(true); try { + // Setup encoding. + $mailer->CharSet = 'UTF-8'; + $mailer->Encoding = 'base64'; + if (DI::config()->get('phpmailer', 'smtp')) { // Set mailer to use SMTP $mailer->isSMTP(); - // Setup encoding. - $mailer->CharSet = 'UTF-8'; - $mailer->Encoding = 'base64'; - // Specify main and backup SMTP servers $mailer->Host = DI::config()->get('phpmailer', 'smtp_server'); $mailer->Port = DI::config()->get('phpmailer', 'smtp_port'); @@ -90,9 +90,14 @@ function phpmailer_emailer_send_prepare(App $a, IEmail &$email) // additional headers if (!empty($email->getAdditionalMailHeader())) { - foreach (explode("\n", trim($email->getAdditionalMailHeader())) as $header_line) { - list($name, $value) = explode(':', $header_line, 2); - $mailer->addCustomHeader(trim($name), trim($value)); + foreach ($email->getAdditionalMailHeader() as $name => $values) { + // Set the "Message-ID" header for PHP-Mailer directly + if (strtolower($name) === 'message-id') { + // implode all values to one entry, because there's only one value possible + $mailer->MessageID = trim(implode("", $values)); + } else { + $mailer->addCustomHeader(trim($name), trim(implode("\n", $values))); + } } }