Member Avatar for doctorphp

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

Maybe you can give a snippet of your code?

Member Avatar for doctorphp

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.

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().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.