Add BCC or CC to all emails the forum sends

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
Erpenator
Registered User
Posts: 40
Joined: Tue Nov 03, 2009 6:45 pm

Add BCC or CC to all emails the forum sends

Post by Erpenator »

I am trying to add an extra email address whenever the cronjobs sends out an email. We are running into several problems with sending emails and I want to better monitor what is going on. I am using phpbb 3.3.0.

I've added

Code: Select all

core.notification_message_email
to one of my existing extensions and add an CC address to the $event['addresses'] to get a CC of any email that is being sent like this:

Code: Select all

$event['addresses'] = array_merge($event['addresses'], array('cc' => array(array('email' => '[email protected]', 'name' => 'Forum'))));
I can see that the

Code: Select all

$event['addresses']
is giving an output that I would expect, but I never receive any emails.

Code: Select all

array(4) {
    ["break"]=>
    bool(false)
    ["addresses"]=>
    array(2) {
      ["cc"]=>
      array(1) {
        [0]=>
        array(2) {
          ["email"]=>
          string(14) "[email protected]"
          ["name"]=>
          string(9) "Forum"
        }
      }
      ["to"]=>
      array(1) {
        [0]=>
        array(2) {
          ["email"]=>
          string(22) "[email protected]"
          ["name"]=>
          string(4) "Username"
        }
      }
    }
If I add another "to" array the email that was previously set will be mailed not the updated / changed email.

For testing purposes I've added

Code: Select all

 $this->addresses['cc'][0]['email'] = trim('[email protected]');
        $this->addresses['cc'][0]['name'] = trim('Forum');
in the constructor of functions_messenger.php (and yes, I know You are not supposed to edit the forum files, but this is just to debug) and that worked.

I can't really find out what I am doing wrong and why emails are not being sent to the CC address that I add via the extension.
rxu
Extensions Development Team
Posts: 3711
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Contact:

Re: Add BCC or CC to all emails the forum sends

Post by rxu »

This can happen because direct assigning to $event variable doesn't work due to overloaded vars. See https://area51.phpbb.com/docs/dev/3.3.x ... -listeners

You have to use local variable like

Code: Select all

$addresses = $event['addresses'];
$addresses = array_merge($addresses, array('cc' => array(array('email' => '[email protected]', 'name' => 'Forum'))));
$event['addresses'] = $addresses;
Erpenator
Registered User
Posts: 40
Joined: Tue Nov 03, 2009 6:45 pm

Re: Add BCC or CC to all emails the forum sends

Post by Erpenator »

Thanks for the reply. I gave your code example a try, but unfortunately that didn't resolved the problem. I am able to find if overloaded vars is causing the issues. Any ideas how to test this? Or other things I could try?
rxu
Extensions Development Team
Posts: 3711
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Contact:

Re: Add BCC or CC to all emails the forum sends

Post by rxu »

Just checked the code. You can't change addresses via core.notification_message_email as the var passed to the event is just a copy of $this->addresses class property. See https://github.com/phpbb/phpbb/blob/0a0 ... r.php#L564

I guess you could use cc / bcc functions to add addresses if you'd find event where current messenger class Instance is passed.
Last edited by rxu on Sat Feb 01, 2020 1:54 pm, edited 1 time in total.
Erpenator
Registered User
Posts: 40
Joined: Tue Nov 03, 2009 6:45 pm

Re: Add BCC or CC to all emails the forum sends

Post by Erpenator »

That could explain it. I am not trying to change the addresses, but just add a CC or BCC to existing notifications that are being send by email. I saw that https://www.phpbb.com/customise/db/exte ... extension/ @markdhamill is using core.modify_email_headers to add changes to the emails. But based on the name and the short description I thought it should be possible to change or at least add a CC with core.notification_message_email
Post Reply

Return to “Extension Writers Discussion”