We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,594 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

PHP Email form

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
16 Hours
Discussion Span
2 Years Ago
Last Updated
4
Views
Question
Answered
doctorphp
Junior Poster in Training
67 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Maybe you can give a snippet of your code?

Daiva
Light Poster
37 posts since May 2009
Reputation Points: 14
Solved Threads: 9
Skill Endorsements: 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.

doctorphp
Junior Poster in Training
67 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

Daiva
Light Poster
37 posts since May 2009
Reputation Points: 14
Solved Threads: 9
Skill Endorsements: 0
Question Answered as of 2 Years Ago by Daiva

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0708 seconds using 2.67MB