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 = "[email protected]"; $subject = "Request"; $body = "Name: " . $name . "\n\n" . "Address: " .$address; $headers = 'From: [email protected]' . "\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 Link to comment https://forums.phpfreaks.com/topic/166646-php-form-remove-rn/ Share on other sites More sharing options...
WolfRage Posted July 20, 2009 Share Posted July 20, 2009 You can also use trim(). Link to comment https://forums.phpfreaks.com/topic/166646-php-form-remove-rn/#findComment-878751 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 Link to comment https://forums.phpfreaks.com/topic/166646-php-form-remove-rn/#findComment-878759 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. Link to comment https://forums.phpfreaks.com/topic/166646-php-form-remove-rn/#findComment-878761 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; } Link to comment https://forums.phpfreaks.com/topic/166646-php-form-remove-rn/#findComment-878763 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! Link to comment https://forums.phpfreaks.com/topic/166646-php-form-remove-rn/#findComment-878778 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); Link to comment https://forums.phpfreaks.com/topic/166646-php-form-remove-rn/#findComment-879322 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. Link to comment https://forums.phpfreaks.com/topic/166646-php-form-remove-rn/#findComment-879598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.