line breaks

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lubber123
Forum Commoner
Posts: 51
Joined: Mon Sep 15, 2008 12:26 pm
Location: Manassas, VA

line breaks

Post by lubber123 »

I am having issues sending mail and changing the line breaks to breaks. I am sending an html email and the line breaks in the mail itself, when received, have \r\n and I have tried using nl2br() but I still get the same result:

Result: test13\r\n\r\ntest13\r\n\r\ntest13

Code: Select all

<p id='message'>" . nl2br($_REQUEST['message']) . "</p>
								  <p id='headers'>
								  From: " . $name . "<br />
								  Subject: " . nl2br($_REQUEST['subject']) . "<br />
								...
					 //Mail it
					if(mail($to, $subject, $message, $headers)){
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: line breaks

Post by social_experiment »

Try using "\r\n\r\n". nl2br inserts <br /> or <br > tags before a new line, you're email message probably just a plain text message which ignores <br /> (or <br >).
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
lubber123
Forum Commoner
Posts: 51
Joined: Mon Sep 15, 2008 12:26 pm
Location: Manassas, VA

Re: line breaks

Post by lubber123 »

what do you mean by -- "\r\n\r\n". nl2br inserts

str_replace or insert in Db and then retrieve - sorry I am lost.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: line breaks

Post by social_experiment »

lubber123 wrote:what do you mean by -- "\r\n\r\n". nl2br inserts
Apparently the line break tag (< br / >) was read as html. Use the value "\r\n\r\n" to create a new line break. the nl2br() function insert line break tags < br / > when a new line is encountered.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply