bcit-ci / CodeIgniter

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
18.27k stars 7.63k forks source link

Email config file ignored due to silent re-initialisation with default variables #2039

Closed Ninegears closed 11 years ago

Ninegears commented 11 years ago

CI silently re-runs email->initialise with default variables AFTER the config file has been successfully run through there, which removes all custom settings.

This means in my case that SMTP settings are ignored and the default sendmail system is used, which is wrecking the application.

The fix I used, to demonstrate the issue (not at all acceptable for most cases but it bypasses the errant re-call):

public function initialize($config = array()) {
    qlog($config, 'initialize $config');
    if ($config['protocol']=='smtp') {
        //the usual code is moved to here
    }
    return $this;

My controller:

    $to = 'an@email.com';

    $this->load->library('email');
    $this->email->from(SITE_EMAIL_ADDRESS, SITE_EMAIL_NAME);
    $this->email->to($to);
    $this->email->subject("testing email system");
    $this->email->message("Hi - we're testing the email connectivity between your server and ours. So if you're seeing this then presumably all went well. Please ignore this message, no action is required on your part.");
    $this->email->send();

    qlog($this->email->print_debugger());

Without my fix, the debugger reports successful send VIA SENDMAIL.

My config file:

$config['protocol'] = 'smtp'; $config['smtp_host'] = 'mail.domain.co.uk'; $config['smtp_user'] = SITE_EMAIL_ADDRESS; $config['smtp_pass'] = SITE_EMAIL_PASSWORD; $config['newline'] = "\r\n"; $config['crlf'] = "\n"; //long subjects break iso spec without this $config['charset'] = 'utf-8'; $config['wordwrap'] = TRUE;

This works perfectly with my fix, so config values are not at fault.

Updated for formatting and to remove a testing email address.

narfbg commented 11 years ago

Tried with both 2.1.3 and 3.0-dev and I'm unable to reproduce this.

narfbg commented 11 years ago

We found out the problem after a lengthy conversation on IRC - turned out another library re-configured the Email class with its own settings.