Welcome Guest, Not a member yet? Register   Sign In
[CI 1.7+] Email Class - useragent not configurable
#1

[eluser]a&w[/eluser]
This is pretty easy to verify if this is a bug or not. Just try to change the useragent and then do print_debugger() and you should see the useragent is not changed.

When you do:
Code:
$this->CI->email->initialize($config);

that will call:
Code:
function initialize($config = array())
    {
        $this->clear();
which then calls
Code:
function clear($clear_attachments = FALSE)
    {
        $this->_subject        = "";
        $this->_body        = "";
        $this->_finalbody    = "";
        $this->_header_str    = "";
        $this->_replyto_flag = FALSE;
        $this->_recipients    = array();
        $this->_headers        = array();
        $this->_debug_msg    = array();

        $this->_set_header('User-Agent', $this->useragent);
So at that point $this->_headers['User-Agent'] is using the original 'CodeIgniter' value.

After doing clear() it then does:
Code:
foreach ($config as $key => $val)
        {
            if (isset($this->$key))
            {
                $method = 'set_'.$key;

                if (method_exists($this, $method))
                {
                    $this->$method($val);
                }
                else
                {
                    $this->$key = $val;
                }
So $this->useragent will get reset at that point, but the
Code:
$this->_set_header('User-Agent', $this->useragent);
occurred already (so $this->_header does not get fixed)

During send() 'X-Mailer' is correctly set:
Code:
function _build_headers()
    {
        $this->_set_header('X-Sender', $this->clean_email($this->_headers['From']));
        $this->_set_header('X-Mailer', $this->useragent);

However later, during _write_headers(), it's using $this->_headers (which is still 'CodeIgniter'):
Code:
function _write_headers()
    {
        if ($this->protocol == 'mail')
        {
            $this->_subject = $this->_headers['Subject'];
            unset($this->_headers['Subject']);
        }

        reset($this->_headers);
        $this->_header_str = "";

        foreach($this->_headers as $key => $val)
        {
            $val = trim($val);

            if ($val != "")
            {
                $this->_header_str .= $key.": ".$val.$this->newline;
#2

[eluser]sophistry[/eluser]
yes, i just hit this bug too - consider it verified. i have posted it in the bug tracker here:

http://codeigniter.com/bug_tracker/bug/6643/

this is how i fixed it - not sure if it is a long-term fix, but it let me set the User-Agent header in my email.

around line 922 in the _build_headers() function you'll see a list of _set_header calls, add this one.
Code:
$this->_set_header('User-Agent', $this->useragent);




Theme © iAndrew 2016 - Forum software by © MyBB