0

Hi there.

I am trying to use a html form to send a PHP email but I am having some problems when I enter the message in the text area. The messages that I send have line breaks in but instead of doing a line break it shows the <br /> and it also shows the \n and \r tags. Is there any way to stop them from showing but still use the line breaks.

Thanks in advance
Cameron

2
Contributors
3
Replies
7
Views
7 Years
Discussion Span
Last Post by Daiva
0

Maybe you can give a snippet of your code?

Yeah sure,

The Form

<select name="email">
<option value="0">- - SELECT - -
<?php echo $options; ?>
</select> 
<br /><br />
Subject: <input type="text" name="subject" size="60"/><br />
Message:<br />
<textarea name="message" cols="70" rows="8" ></textarea><br />
<input type="submit" name="send" value="Send" />
</form>

The PHP

$headers = "From: $from";


$to = $_POST['email'];
$to = stripslashes($to);
$to = mysql_real_escape_string($to);

$subject = $_POST['subject'];
$subject = stripslashes($subject);
$subject = mysql_real_escape_string($subject);

$message = $_POST['message'];
$message = nl2br($message);
$message = mysql_real_escape_string($message);

$submit = $_POST['submit'];


   


    


  
    mail($to, $subject, $message, $headers);

Any help would be much appreciated.

1

Firstly thanks for your code.
As I understand, your problem is because of nl2br(). Read carefully what it does and you will see that it is not what you want :]
A simple textarea will save line breaks and in your email you should see them without using nl2br().

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.