Use 2 email configuration |
I need to change email accounts, send them, and then return to the default settings.
I know that it is possible to modify configurations on the fly by passing an array of values to $this->email->initialize($ config); Is there a way to have two or more different configurations, or do you have a way to return to the default configurations without having to initialize everything with the default parameters? Thanks
The main email config file - APPATH/config/email.php - can only contain one set of options. but you can create other config files and load them explicitly passing those values to email->initialize().
But you will have to retrieve APPATH/config/email.php values and send them to $this->email->initialize($ config); to return to the default setup. No way around that I can see.
(10-31-2017, 08:47 AM)dave friend Wrote: The main email config file - APPATH/config/email.php - can only contain one set of options. but you can create other config files and load them explicitly passing those values to email->initialize().I think I'm wrong, I created a file for configuring the second account, load it with $this->config->load(), then call $this->email->initialize($config), but I do not get what I expect, I'm definitely mistaken, can you help me? Thanks
11-06-2017, 11:38 AM
(This post was last modified: 11-06-2017, 11:39 AM by ivantcholakov. Edit Reason: fixing a directory name )
I got interested on how I would do this and here is something I've just tested.
1. Create within the config/ folder two configuration files, email.php and email_2.php and fill them with the corresponding data for the two email accounts. 2. Within libraries/ directory create a file Email_2.php with the following content: Code: <?php defined('BASEPATH') OR exit('No direct script access allowed'); 3. Within the controller Welcome.php or other controller test with this fragment of code: Code: $this->load->library('email'); You would see that both library instances have different properties, according to their configuration files.
I sincerely wanted to avoid too many turns and requests for instances, I did a try like this:
I've created in addition to the default file email.php in the config folder, a second file with the other configuration. so to use the second account I do so: Code: $config_pec = $this->config->load('email_pec', true); Send the amil I need, and then to return to the initial configuration, I do the same thing by referring to the default email.php file Can it be a solution? Do you see things that could also cause problems in the future? |
Welcome Guest, Not a member yet? Register Sign In |