Welcome Guest, Not a member yet? Register   Sign In
email class, quote not working in reply_to ? (CI 1.7.1)
#1

[eluser]hugle[/eluser]
Hello Everyone,

I've been using email class several times, it was ok, but now I've met a problem I will describe:

I want to use quotes (") in `reply_to` and `from`, but the quotes in `reply_to` get missed,

simple example:
Code:
$this->email->to($address);
$this->email->from('[email protected]', "UAB \"test\"");
$this->email->reply_to('[email protected]', "UAB \"test\"");
$this->email->subject('test subject');
$this->email->message('html body');
$this->email->set_alt_message('text body');
$this->email->send();

and in message source I see:
From: "UAB \"test\"" <[email protected]>
Reply-To: "UAB " test "" <[email protected]>

From: seems to be OKAY
but Reply-To: is not Sad

I also tried:
Code:
$this->email->from('[email protected]', 'UAB "test"');
$this->email->reply_to('[email protected]', 'UAB "test"');
-- same result


Can anyone help me to deal with that?Sad

thank you, everyone!
Jaroslav
#2

[eluser]hugle[/eluser]
Hello again,

after some time I decided to dig the function to and function reply_to in the Email class.
I have coppied the code from 'function to'
Code:
// prepare the display name
        if ($name != '')
        {
            // only use Q encoding if there are characters that would require it
            if ( ! preg_match('/[\200-\377]/', $name))
            {
                // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes
                $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"';
            }
            else
            {
                $name = $this->_prep_q_encoding($name, TRUE);
            }
        }
and pasted it to 'funcrion reply_to' and it worked for me...
so I made the extention for CI.

Simply create a file called MY_Email.php in application/libraries
the content of file would be:
Code:
&lt;?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Email extends CI_Email {

    function MY_Email() {
        parent::CI_Email();
    }
    
    function reply_to($replyto, $name = '')
    {
        if (preg_match( '/\<(.*)\>/', $replyto, $match))
        {
            $replyto = $match['1'];
        }

        if ($this->validate)
        {
            $this->validate_email($this->_str_to_array($replyto));
        }

        if ($name == '')
        {
            $name = $replyto;
        }
        
        // prepare the display name
        if ($name != '')
        {
            // only use Q encoding if there are characters that would require it
            if ( ! preg_match('/[\200-\377]/', $name))
            {
                // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes
                $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"';
            }
            else
            {
                $name = $this->_prep_q_encoding($name, TRUE);
            }
        }

        if (strncmp($name, '"', 1) != 0)
        {
            $name = '"'.$name.'"';
        }

        $this->_set_header('Reply-To', $name.' <'.$replyto.'>');
        $this->_replyto_flag = TRUE;
    }
        
}
?&gt;

That should fix your problem if you have one Smile

Good luck and thank you for CI!
#3

[eluser]sophistry[/eluser]
this is a bug. you should post it in the bug tracker.

the from() function and the reply_to() function both handle emails so they should be applying all the same transformations equally. a comprehensive solution wouldnot be the fix you suggested (copy/paste code sections) but a refactoring of the way the class handles email header fields. the Return-Path header is unworkable too, BTW. see this bug report about Return-Path.

nice catch.




Theme © iAndrew 2016 - Forum software by © MyBB