Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Obfuscated Email Subject Issue

May 07, 2010 2:37pm

Subscribe [8]
  • #1 / May 07, 2010 2:37pm

    whobutsb's avatar

    whobutsb

    126 posts

    I’m writing an emailing class for a surveying application i’m coding.  Whenever I add the subject variable in to $this->CI->email->subject(); method it obfuscates the subject.

    Here is my code:

    $this->CI->email->from('me@somewhere.com', 'Me'); 
            $this->CI->email->reply_to('me@somewhere.com', 'Me');  
            
            $this->CI->email->to('someone@somewhere.com'); 
        
            $this->CI->email->subject($distribution->emailSubject); 
            $this->CI->email->message($distribution->emailBody);
    
    $this->CI->email->send();

    The variable $distribution->emailSubject should look like “How was your meal?  Let us know and earn 20 points!”.  But in my subject line of my email client it looks like: “=?utf-8?Q?_How_was_your_meal=3f__Let_us_know_and_earn_20_Points_on_Fare_ X-Sender:”

    Has anyone run into a situation like this?

  • #2 / May 07, 2010 2:41pm

    WanWizard's avatar

    WanWizard

    4475 posts

    This is how it should be. It tells the mail client receiving the email that the subject text uses utf-8 encoding, as per RFC 1342.

  • #3 / May 07, 2010 2:57pm

    whobutsb's avatar

    whobutsb

    126 posts

    Now when I type in the subject directly in to the email->subject method, the subject line looks fine.  Why would it look different if I’m putting in a variable that says the same exact thing?

  • #4 / May 07, 2010 3:14pm

    WanWizard's avatar

    WanWizard

    4475 posts

    The subject will always be q-encoded, in case it contains non-ascii characters (7bit), an underscore, an equals sign, or a question mark.

    So “How was your meal?  Let us know and earn 20 points!” will always be encoded, no matter how you pass it to $this->email->subject().

    from the Email library:

    function subject($subject)
    {
        $subject = $this->_prep_q_encoding($subject);
        $this->_set_header('Subject', $subject);
    }
  • #5 / May 07, 2010 3:23pm

    whobutsb's avatar

    whobutsb

    126 posts

    I see, but why would it look differently from if I just write it in directly?  Is there any way for me to fix my error?

  • #6 / May 07, 2010 3:41pm

    WanWizard's avatar

    WanWizard

    4475 posts

    What do you mean by ‘write it in directly’?

    $this->email->subject('How was your meal?  Let us know and earn 20 points!');

    is exactly the same as

    $var = 'How was your meal?  Let us know and earn 20 points!';
    $this->email->subject($var);
  • #7 / May 07, 2010 3:42pm

    whobutsb's avatar

    whobutsb

    126 posts

    Correct, but when I use the variable method.  The subject line gets printed as: =?utf-8?Q?_How_was_your_meal=3f__Let_us_know_and_earn_20_Points_on_Fare_ X-Sender:

  • #8 / May 07, 2010 4:04pm

    WanWizard's avatar

    WanWizard

    4475 posts

    Yes, as it should be. The only thing that puzzles me is the ‘X-Sender:’ at the end, which should be on the next line.

    Where do you get this subject line from? From the header of your mail client? Which mail client?

  • #9 / May 07, 2010 4:10pm

    whobutsb's avatar

    whobutsb

    126 posts

    This is the exact subject line from Apple Mail:
      =?utf-8?Q?_How_was_your_meal=3f__Let_us_know_and_earn_20_Points_on_Fare_ X-Sender: .(JavaScript must be enabled to view this email address)

    (I removed the actual email address in the subject line).  If you are interested in me forwarding you the message, just send me a quick email to (my forum username)@gmail.com, that way I can send you all the header information.

    Thank you for your help btw.

  • #10 / May 07, 2010 4:32pm

    WanWizard's avatar

    WanWizard

    4475 posts

    Sounds more like an issue with your email client. What happens if you send that exact same email to your gmail account?

    If I send an email out with that subject line to the mail systems I have here (imap/squirrelmail & exchange 2010/Outlook 2010), both show the header in q-encoding, and display the subject properly.

    see if

    $this-email->newline  = "\r\n";

    will help…

  • #11 / May 07, 2010 4:37pm

    whobutsb's avatar

    whobutsb

    126 posts

    Same thing in my Gmail.
    I setup a config file in my config directory called email.php, is that the correct way to name a config file?

    Here is the config I have in that:

    $config['useragent']    = 'NHC SurveyForce'; 
    $config['smtp_host']     = '*******'; 
    $config['protocol']     = 'smtp'; 
    
    $config['smtp_user']    = '*****'; 
    $config['smtp_pass']     = '*******'; 
    $config['smtp_port']     = 25; 
    $config['mailtype']     = 'html'; 
    $config['newline']        = "\r\n";
    $config['crlf']            = "\r\n";
    $config['charset']        = "utf-8";
  • #12 / May 07, 2010 4:47pm

    WanWizard's avatar

    WanWizard

    4475 posts

    Don’t see anything wrong with that.

    What happens if you do a $this->email->print_debugger() directly after a $this->email->send()? And a var_dump($this->email->_header_str)?

  • #13 / May 07, 2010 4:50pm

    whobutsb's avatar

    whobutsb

    126 posts

    For the print_debugger the subject line is still coming across screwed up. 

    Would it be terrible if I commented out the $subject = $this->_prep_q_encoding($subject);  line the CI email library?

  • #14 / May 07, 2010 4:57pm

    WanWizard's avatar

    WanWizard

    4475 posts

    If that’s the case then it looks like your “\r\n” isn’t used as newline.

    Try

    $this-email->newline  = "\r\n";

    before you compose your email.

    You could comment it out, it’s not a problem as long as your subjects are ASCII characters only. I would advise you to find the problem, instead of working around it (and possibly introduce other issues).

  • #15 / May 07, 2010 5:04pm

    whobutsb's avatar

    whobutsb

    126 posts

    No go on just using the $this->email->newline = “\r\n”;

    Hmm I will keep working on it. Thank you for your help!  If anyone else has any ideas, I’d love to hear them!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases