CodeIgniter Forums

Full Version: Obfuscated Email Subject Issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3

El Forum

[eluser]whobutsb[/eluser]
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:
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?

El Forum

[eluser]WanWizard[/eluser]
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.

El Forum

[eluser]whobutsb[/eluser]
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?

El Forum

[eluser]WanWizard[/eluser]
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:
Code:
function subject($subject)
{
    $subject = $this->_prep_q_encoding($subject);
    $this->_set_header('Subject', $subject);
}

El Forum

[eluser]whobutsb[/eluser]
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?

El Forum

[eluser]WanWizard[/eluser]
What do you mean by 'write it in directly'?

Code:
$this->email->subject('How was your meal?  Let us know and earn 20 points!');
is exactly the same as
Code:
$var = 'How was your meal?  Let us know and earn 20 points!';
$this->email->subject($var);

El Forum

[eluser]whobutsb[/eluser]
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:

El Forum

[eluser]WanWizard[/eluser]
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?

El Forum

[eluser]whobutsb[/eluser]
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: info@mywebsite.com

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

El Forum

[eluser]WanWizard[/eluser]
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
Code:
$this-email->newline  = "\r\n";
will help...
Pages: 1 2 3