Skip to content
Permalink
Browse files

BCC all outgoing mails when it's configured. Ref #397

  • Loading branch information...
mke-tb authored and Traumflug committed Aug 31, 2019
1 parent e512244 commit 6847b0cff859b226493e14b0e99d42dcd4031a45
Showing with 31 additions and 2 deletions.
  1. +30 −1 classes/Mail.php
  2. +1 −1 controllers/admin/AdminEmailsController.php
@@ -199,11 +199,40 @@ public static function Send(
$to = Tools::convertEmailToIdn($to);
}
// if bcc is not null, make sure it's a vaild e-mail
// If $bcc is not null, make sure it's a valid e-mail
if (!is_null($bcc) && !is_array($bcc) && !Validate::isEmail($bcc)) {
static::logError(Tools::displayError('Error: parameter "bcc" is corrupted'), $die);
$bcc = null;
}
// Check if there is any configuration for emails to add as BCC to all outgoing emails
$bccMails = [];
$bccAllMailsTo = Configuration::get('TB_BCC_ALL_MAILS_TO', null, null, $idShop);
if (!empty($bccAllMailsTo)) {
// If there is no delimiter character (;), initialize bcc emails with the input value,
// otherwise initialize it by exploding the value into an array of emails.
// Note that we assume all emails were already validated when they were being saved.
if (strpos($bccAllMailsTo, ';') !== false) {
$bccMails = explode(';', $bccAllMailsTo);
} else {
array_push($bccMails, $bccAllMailsTo);
}
}
// If there is at least one email or more to add to the bcc field, add to $bcc.
if (count($bccMails) > 0) {
// If $bcc is null, initialize it with bccMails array.
if (is_null($bcc)) {
$bcc = $bccMails;
} else {
// If $bcc is not null, convert it to an array if it isn't already.
if (!is_array($bcc)) {
$bcc = [ $bcc ];
}
// Add additional bcc addresses to $bcc.
array_push($bcc, array_values($bccMails));
}
}
if (is_array($bcc)) {
foreach ($bcc as &$address) {
$address = Tools::convertEmailToIdn($address);
@@ -387,7 +387,7 @@ public function beforeUpdateOptions()
}
if (isset($_POST['TB_BCC_ALL_MAILS_TO']) && !empty($_POST['TB_BCC_ALL_MAILS_TO'])) {
// If there are no delimiter character (;), initialize bcc mails with the input value,
// If there is no delimiter character (;), initialize bcc mails with the input value,
// otherwise initialize by exploding the value into an array of (non-validated) emails.
$bccMails = [];
if (strpos($_POST['TB_BCC_ALL_MAILS_TO'], ';') !== false) {

0 comments on commit 6847b0c

Please sign in to comment.
You can’t perform that action at this time.