• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
n character added in html emails

I am trying to send html emails.

The email class is initiated via a config file which contains:
$config['protocol'] = 'sendmail';
    $config['mailtype'] = 'html';
    $config['newline'] = "\n";
    $config['crlf'] = "\n";

The message is created with a jquery-based rich text editor. The output is clean html and is stored in a database. The test message is:

this is the first line</p>
this is the secon dline</p>
and this is the third line</p>

and the resulting message:

n this is the first line

n this is the secon dline

n and this is the third line

I've tried using \r\n instead and it doesn't make any difference.

Any ideas would be greatly appreciated.

And what does it look like if you just read it from the database and echo it out?

Sounds like your text editor is adding those on.

An escaped n ("\n") works fine as a newline in plain text emails. But in HTML emails it's just, well an "n".

Before sending your emails in HTML format run the text through the PHP function nl2br() and it will convert those newline chars to HTML-friendly BR tags.

insiteFX: the html message I posted is what is stored in the database ... that is what was delivered by the RTE.

kanjimaster: thank you for that bringing that function to my attention ... however I don't know where to use it. I am sending the email class clean HTML ... those n's are added by it, not by me.


And, your "n"s are actually added by you, whether you realize it or not. They are invisible new-line control characters, which get entered whenever you hit the return key, such as in a textbox. Every single text document you write has them. Open any of your docs in a text editor that shows invisible characters and you will see them at the end of each line, or wherever you've hit enter/return. If they weren't there, the text in your document would be contained on a single line.

Check your text editor configuration it is probably saving /n where it should be saving

Most text editor allow you to configure it.

Thank you CroNIX and insiteFX. Indeed I found a way to configure the editor to not add anything in new lines. So the problem has disappeared.

I can understand the \n char being injected in simple text editing. Still I am not clear on why when everything is configured for HTML editing why:
1. An HTML editor would inject non-HTML elements at all, especially as a default configuration.
2. If CI Email is set to HTML wouldn't it make sense for it to do that stripping for me (and alternately to add them for me if using text mode ... as its settings seem to suggest id will do)?

Both seem to go against my common sense (which granted may be wrong) and in both cases reverse decisions seems like double-fail-proofing (rather then injecting a fault).

Thank you everyone for your super-fast and super-supportive attention and guidance.

An HTML editor still needs some non-printing characters, like newlines and tabs to know how to format your HTML when your editing it. But personally, I don't think that's where the problem was originating.

I'd look instead at the config settings you gave us in your original post, where you appeared (unintentionally I'm sure) to be telling CI that you wanted emails to go in HTML format but with ascii newline chars rather than HTML br tags.

there are legitimate HTML codes for newlines and tabs ... and in my examplen neither was called for since there were three paragraphs inclosed in valud <p> tags which the editor put in properly. If I did put in a new line than that should have been injected as an HTML code ... then later, when a text-version of the email was generated CI should have simply replaced those with what ever its settings indicate.

The CI settings, I believe, are misleading. From what I understand they have nothing to do with the HTML formatting. They are only needed for TEXT emails (whether explicitly selected or provided as an alterior format when sendind HTML emails). For example, you cannot set the newline to be "<br/>" ... because it will default back to "\n" (I checked the Email class code). Those settings simply have nothing to do with HTML emails ... it would be helpful if the documentation indicated this.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.