Best way of setting a global email recipient


What is the preferred method for setting a global variable for the recipient of the email class?

I've tried to do it in the email config file, but that doesn't seem to work:

$config['to'] = '[email protected]';

Basically, all the emails from the site I'm building are only ever going to be going to one address, and I'd like an easy way of maintaining that address should it need to change.


[eluser]Référencement Google[/eluser]
Can you post your code so we can help?


Well, I've got a few controllers that make use of the Email class, and I construct the rules like so:

// Set email rules
$this->email->from('[email protected]', 'someone');
$this->email->to('[email protected]');
$this->email->message('How are you?');

So rather than me having to set the:

$this->email->to('[email protected]');

.. in each controller, I'd like to have it globally defined somewhere, ideally in the Email config file, so that ALL email's sent from the Email class will go to that recipient. Otherwise, if the recipients email changes, I've then got to go through each of the controllers and change it, rather than just making the change in a centralised file.


[eluser]Référencement Google[/eluser]
The user guide says this:

Quote:Setting Email Preferences in a Config File

If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called the email.php, add the $config array in that file. Then save the file at config/email.php and it will be used automatically. You will NOT need to use the $this->email->initialize() function if you save your preferences in a config file.

Have you tried it exactly like it is explained?

Yes. And the 'to' method is not part of the preferences. It's a method.

[eluser]Référencement Google[/eluser]
I see then 2 possible solutions to this:

- Set a $config['mail_to'] = '[email protected]'; and fetch it with $this->config->item('mail_to') where necessary (I didn't tested if it was possible to fetch it like it when you put this config in the config/email.php file

- Set a constant in your config file (or in the constants.php file): define('MAIL_TO', '[email protected]');

Maybe someone will have a better solution to this, but that's how I would do it.

Thanks - they were the types of possible solutions I was after. Just didn't know if there was a best practice to this sort of thing?

[eluser]Référencement Google[/eluser]
There is nothing wrong using them.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.