Gainax Posted July 20, 2009 Share Posted July 20, 2009 I have a form, which takes the input and when submitted it sends an email to me with the content. One field is a textarea and when I get the email I get \r\n where someone has gone onto a newline in the text area. My form is: <form id="requestform" name="requestform" method="post" action=""> <p><label for="name">Name:*</label><br /> <?php echo (($nameOK) ? "" : "<p style=\"color:red;\"><strong>Invalid Name: </strong> Your name must be at least 3 letters<br /></p>"); ?> <input name="name" class="text" type="text" id="name" value="<?=$_POST['name'] ?>" /></p> <p><label for="address">Address:*</label><br /> <?php echo (($addressOK) ? "" : "<p style=\"color:red;\"><strong>Invalid Address: </strong> Please enter your full address<br /></p>"); ?> <textarea name="address" class="text" name="address" cols="30" rows="5" value="<?=$_POST['address'] ?>" ></textarea><br /></p> <button type="submit" name="send" value="send" style="height: 26px; width: 96px; border: 0px;" ><img src="images/send_request.jpg" alt="send" title="" /></button> And the code which takes the form data is: <?php if( isset($_POST['send'])) { $nameOK = validateName($_POST['name']); $addressOK = validateAddress($_POST['address']); if ($nameOK && $addressOK ) { $to = "example@example.com"; $subject = "Request"; $body = "Name: " . $name . "\n\n" . "Address: " .$address; $headers = 'From: example@example.co.uk' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); if (mail($to, $subject, $body, $headers)) { header('Location: thankyou.php'); } else { I've tried using nl2br around the $address variable, but I still get the \r\n after each linebreak Am I doing anything wrong? Thanks Quote Link to comment Share on other sites More sharing options...
WolfRage Posted July 20, 2009 Share Posted July 20, 2009 You can also use trim(). Quote Link to comment Share on other sites More sharing options...
Gainax Posted July 20, 2009 Author Share Posted July 20, 2009 I tried that too, and it didn't work Quote Link to comment Share on other sites More sharing options...
WolfRage Posted July 20, 2009 Share Posted July 20, 2009 Can we see the code for the validate address function. Quote Link to comment Share on other sites More sharing options...
Gainax Posted July 20, 2009 Author Share Posted July 20, 2009 function validateAddress($address){ //if it's NOT valid if(strlen($address) < 4) return false; //if it's valid else return true; } Quote Link to comment Share on other sites More sharing options...
WolfRage Posted July 20, 2009 Share Posted July 20, 2009 LOL ok, well that was simple. Let's see your code that is using the functions nl2br() and or trim() so I can look it over for errors. Warning going to lunch soon! Quote Link to comment Share on other sites More sharing options...
Gainax Posted July 21, 2009 Author Share Posted July 21, 2009 I had the following code: $body = "Name: " . $name . "\n\n" . "Address: " .trim($address); and then tried: $body = "Name: " . $name . "\n\n" . "Address: " .nl2br($address); Quote Link to comment Share on other sites More sharing options...
WolfRage Posted July 21, 2009 Share Posted July 21, 2009 well according to everything you provided which was not much, then your php setup must not support these popular functions. Because trim be default will strip both of the characters you are trying to remove. Or you can post more of your code for error checking. Also you may want to do some htmlspecialchars() to make sure html is not being injected. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.