Skip to content

Commit

Permalink
BCC all outgoing mails when it's configured. Ref #397
Browse files Browse the repository at this point in the history
  • Loading branch information
mkerd committed Sep 2, 2019
1 parent 1da7c0e commit 561aec2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion classes/Mail.php
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminEmailsController.php
Expand Up @@ -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) {
Expand Down

0 comments on commit 561aec2

Please sign in to comment.