tobyhutton Posted April 25, 2011 Share Posted April 25, 2011 Hi there, I'm not really a php person more asp. I have to write an html send mail script. The email sends and receives perfect. When a user writes the message in the <textarea> box I need to be able to write a new line, so when they press enter and blank line will show in the textarea, how can I write <br> for every blank line. Heres my code so far..... <?php $from = $_POST['email']; $to = "[email]person@domain.com[/email]"; $subject = $_POST["subject"]; $name = $_POST['name']; $location = $_POST['location']; $message = $_POST['message']; $HTML = "<font size=2 face=arial><b><u>" . $name ." from " . $location . "</font></u></b>"; $HTML = $message sendHTMLemail($HTML,$from,$to,$subject); function sendHTMLemail($HTML,$from,$to,$subject) { $headers = "From: $from\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $boundary = uniqid("HTMLEMAIL"); $headers .= "Content-Type: multipart/alternative;". "boundary = $boundary\r\n\r\n"; $headers .= "This is a MIME encoded message.\r\n\r\n"; $headers .= "--$boundary\r\n". "Content-Type: text/plain; charset=ISO-8859-1\r\n". "Content-Transfer-Encoding: base64\r\n\r\n"; $headers .= chunk_split(base64_encode(strip_tags($HTML))); $headers .= "--$boundary\r\n". "Content-Type: text/html; charset=ISO-8859-1\r\n". "Content-Transfer-Encoding: base64\r\n\r\n"; $headers .= chunk_split(base64_encode($HTML)); mail($to,$subject,"-f",$headers); } ?> The $message is the message the user writes. Any Thoughts Thanks Quote Link to comment https://forums.phpfreaks.com/topic/234682-php-html-email/ Share on other sites More sharing options...
wildteen88 Posted April 25, 2011 Share Posted April 25, 2011 Use nl2br when sending the email. Quote Link to comment https://forums.phpfreaks.com/topic/234682-php-html-email/#findComment-1206004 Share on other sites More sharing options...
tobyhutton Posted April 25, 2011 Author Share Posted April 25, 2011 Sorry but how would I write this. Would this do the trick <?php echo nl2br(". $_POST['message']); ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/234682-php-html-email/#findComment-1206014 Share on other sites More sharing options...
dcro2 Posted April 25, 2011 Share Posted April 25, 2011 No.. that would just print the code onto the page in your browser. You have to join your html with what nl2br outputs: $HTML = "<font size=2 face=arial><b><u>" . $name ." from " . $location . "</font></u></b><br><br>\n"; $HTML .= nl2br($_POST['message']); Don't know if you know about string concatenation so here's a link on what it is: http://php.net/manual/en/language.operators.string.php Quote Link to comment https://forums.phpfreaks.com/topic/234682-php-html-email/#findComment-1206118 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.