CodeIgniter Forums

Full Version: New lines in text versions of html emails
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Craig300[/eluser]
Hi All,

I seem to be having a major problem trying to insert line breaks (ie \n) into the text versions of my html emails. I have generated this text version so that CI doesn't have to create them from the html version but for some unknown reason, when I get the text version to my phone, it isn't changing the \n into actual lines breaks.

I have had a look through the CI email class and changed a few bits but to no success.

Can anyone suggest what could be causing this and how it be sorted?

Cheers

Craig

El Forum

[eluser]mddd[/eluser]
Some possible solutions:
- Have you used double quotes? "\n" should give you a line ending while '\n' will not.
- Use a view to generate the text version (and for the html version, btw). That works well, in my experience.
Code:
$this->email->message( $this->load->view('email_text', $data, true) );

El Forum

[eluser]Craig300[/eluser]
Cheers for your response,

I have since had a play around with the email class and changed something which seems to have fixed it. I have already put each emails into their own view as you said but for some unknown reason, it is working without the need to do \n or \r\n and just put normal spaces in. Bizarre!!!

El Forum

[eluser]mddd[/eluser]
In the past I have experienced that lines ending with a php tag don't get newlines after them.
For instance the following view code
Code:
Hello <?=$name?>
How are you?
(with no space at the end of the first line) would give the output
Code:
Hello JohnHow are you?
If you put a space after the closing ?> tag, it would output
Code:
Hello John
How are you?
as expected.

El Forum

[eluser]Craig300[/eluser]
I have just tried that 'trick' and it works but I don't understand how just putting a single space after the closing php tags that this would allow it to create a line break - how very odd.

I shall have to remember this trick for when I'm bashing my head against a brick wall in the future Smile

Cheers for your help Smile

El Forum

[eluser]mddd[/eluser]
I'm not sure. I think the php parser reasons that there is 'nothing' after the variable. And 'nothing' also means: no line ending.
While, when there is a space, there is 'something'..

El Forum

[eluser]Craig300[/eluser]
That sounds the most reasonable answer to this problem just weird that when spaces after ending php tags usually break things, in this case, it has fixed them Smile

I might have a look into this in the future and see if I can come up with a definite explanation.