Welcome Guest, Not a member yet? Register   Sign In
Use 2 email configuration
#1

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
Reply
#2

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.
Reply
#3

(This post was last modified: 11-06-2017, 08:16 AM by serialkiller.)

(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().

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.
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
Reply
#4

(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');

get_instance()->load->library('email');

// This name could be 'CI_Email' or 'MY_Email', or something else as a result.
$_email_class_name = get_class(get_instance()->email);

class_alias($_email_class_name, '_Email_2');

class Email_2 extends _Email_2 {

}

3. Within the controller Welcome.php or other controller test with this fragment of code:
Code:
$this->load->library('email');
        var_dump(get_object_vars($this->email));

        echo '<br />';

        $this->load->library('email_2');
        var_dump(get_object_vars($this->email_2));

You would see that both library instances have different properties, according to their configuration files.
Reply
#5

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);
$config_pec = $this->config;
// Send new config to email class
$this->email->initialize( $config_pec->config['email_pec'] );

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?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB