0

I am currently developing a website with the help of codeigniter and the ion auth library.

I am trying to use ion auth's standard functionality to reset a users password.

In the library there are 2 functions:

  • forgotten_password($identity)
  • forgotten_password_complete($code)

Both functions (in case validation goes through) send an email to the user. The functions themselves work, but the emails i receive are broken. The emails header is displayed as a part of the emails body. This is how a broken email looks:

Date: Fri, 18 Nov 2011 23:36:32 +0100

From: "Example.com" <admin@example.com>

Reply-To: "admin@example.com" <admin@example.com>

X-Sender: admin@example.com

X-Mailer: CodeIgniter

X-Priority: 3 (Normal)

Message-ID: <4ec6ddf0d26a3@example.com>

Mime-Version: 1.0

Content-Type: multipart/alternative; boundary="B_ALT_4ec6ddf0d26b9"






This is a multi-part message in MIME format.

Your email application may not support this format.



--B_ALT_4ec6ddf0d26b9

Content-Type: text/plain; charset=utf-8

Content-Transfer-Encoding: 8bit



New Password for test_user



Your password has been reset to: 0774b65f5e





--B_ALT_4ec6ddf0d26b9

Content-Type: text/html; charset=utf-8

Content-Transfer-Encoding: quoted-printable



<html>
<body>
    <h1>New Password for test_user</h1>
=09
    <p>Your password has been reset to: 0774b65f5e</p>
</body>
</html>



--B_ALT_4ec6ddf0d26b9--

However I was able to track down the line which is causing the trouble:

$this->ci->email->set_newline("\r\n");

When I comment out this line (in both functions mentioned above), the emails I receive when I reset a users password are fine.

Can someone explain to me the purpose of this line and wether or not it is a good idea to solve this problem by just commenting the line out.

I also found 2 questions

referring to the same or at least a similar problem. As they are fairly old and haven't been answered yet, I created a new one. Hope no one minds.

Community
  • 1
  • 1
mwallisch
  • 1,751
  • 2
  • 21
  • 29

2 Answers2

3

Different operating systems use different characters to determine a new line (the place at which a line breaks to the next line.) In HTML, the equivalent is the <br> tag. Some (old? Mac) traditionally use \r, some (Unix) traditionally use \n, and others (Windows) traditionally use both (\r\n).

Codeigniter defaults to \n (see documentation), but the writer of ion auth overrode that to use \r\n, which is the standard.

So, the program parsing the email headers (which at my best guess is *nix-based) sees the non-Unix-standard \r\n line and starts spitting the headers out as part of the body.

To the best of my knowledge, you'll get by fine with just \n, which is why Codeigniter defaults to it. Every instance I've seen of people with troubles have been people using \r\n and getting the same problem you're having.

Matt Stauffer
  • 2,706
  • 15
  • 20
1

In CI, that setting defaults to '\n' when you comment that line out. The setting depends on the mail server that's being used by PHP. Sometimes postfix and some other servers will replace \r\n with \r\r\n causing errors, so in these cases it's best to just use \n, since the standard (RFC 822) requires \r\n.

Steve Lewis
  • 1,302
  • 7
  • 8