Forum Moderators: coopster

Message Too Old, No Replies

New lines being stripped out of php mail()

         

smithaa02

5:03 pm on Aug 19, 2005 (gmt 0)

10+ Year Member



I send out a text email with newlines, and some of them get stripped out.

What I'm working on is an app that stores text area text into a database, and then mails the database contents out in a text email. The newlines do show up when I check the table contents in phpMyAdmin, but do not when I sent the contents as an email.

Does anybody know what would cause mail() to strip out newlines?

jatar_k

5:08 pm on Aug 19, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I assume you are just using \n

is it a mail client on a windows machine? I have seen some (and only some) complain about \n alone and require \r\n

smithaa02

5:16 pm on Aug 19, 2005 (gmt 0)

10+ Year Member



I assume you are just using \n

is it a mail client on a windows machine? I have seen some (and only some) complain about \n alone and require \r\n

I'm not sure if it is \n or \r\n or whatever... Does anybody know what the default is for newlines entered into form text areas? The client is outlook 2003. Do you think I should do a find for \n and replace with \r?

jatar_k

5:31 pm on Aug 19, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



use both together

\r\n

instead of just \n

I wouold test it before oyu start finding and replacing things ;)

smithaa02

5:41 pm on Aug 19, 2005 (gmt 0)

10+ Year Member



How would you know if you had \r\n or just \n? I executed the following to no avail:

ereg_replace("\n","\r\n",@mysql_result(mysql_query("select * from table"),0,"emailfield"));

(I put that in the body of my email.)

I'm tempted to use an html mime type and use pre's to send out the email, but long lines don't wrap in outlook. Anybody know how to get this to work?

jatar_k

8:43 pm on Aug 19, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could go with html email and use nl2br() [php.net] on the content submitted in the textarea also

smithaa02

2:18 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



I think I found the problem. Outlook has a 'Remove extra line breaks' feature set to default. Because it would be impractical for me to have each client change their outlook settings, does anybody know a php mail() hack that would protect these extra link breaks? I know, I know, I could use html emails, but the html mime type scores points on most spam filters, and because I don't need html formatting, I would rather not use it.

MatthewHSE

10:21 pm on Aug 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



With extra line breaks removed, doesn't the text wrap pretty neatly anyway? I wouldn't know how to get around this with plain-text e-mail; it might just be better to live with it! ;)