textarea - How to convert carriage returns into line breaks in php when I receive the email? -
i have website form. form submitted email address can read there. i've been testing sending myself emails, when receive message , expect example:
name: guy
number: 123456789
email: someguy@someweb.com
message:
croissant liquorice macaroon. jujubes cupcake cupcake cupcake cotton candy danish. muffin croissant apple pie.
chupa chups jelly-o oat cake sugar plum croissant tootsie roll. candy canes topping lemon drops. gummies jelly gummies brownie halvah sesame snaps candy canes applicake.
marshmallow caramels sugar plum jelly macaroon sesame snaps danish powder sesame snaps. bonbon liquorice muffin liquorice cotton candy dessert oat cake. cotton candy caramels dessert cake pie jelly beans tiramisu. cake applicake tiramisu muffin macaroon pie donut.
i receive them this:
croissant liquorice macaroon. jujubes cupcake cupcake cupcake cotton candy danish. muffin croissant apple pie. chupa chups jelly-o oat cake sugar plum croissant tootsie roll. candy canes topping lemon drops. gummies jelly gummies brownie halvah sesame snaps candy canes applicake. marshmallow caramels sugar plum jelly macaroon sesame snaps danish powder sesame snaps. bonbon liquorice muffin liquorice cotton candy dessert oat cake. cotton candy caramels dessert cake pie jelly beans tiramisu. cake applicake tiramisu muffin macaroon pie donut.
all line breaks gone , message 1 straight line.
i'm not yet familiar php if can me in easiest way possible appreciated.
here php comment section code:
<?php //if form submitted if(isset($_post['submit'])) { $emailtext = $_post['message']; str_replace("\r", "\n", $emailtext); //check make sure name field not empty if(trim($_post['contactname']) == '') { $haserror = true; } else { $name = trim($_post['contactname']); } //check make sure sure valid email address submitted if(trim($_post['email']) == '') { $haserror = true; } else if (!eregi("^[a-z0-9._%-]+@[a-z0-9._%-]+\.[a-z]{2,4}$", trim($_post['email']))) { $haserror = true; } else { $email = trim($_post['email']); } //check make sure sure phone number submitted if(trim($_post['phone']) == '') { $haserror = true; } else if (!preg_match("/^[1-9][0-9]{0,10}$/", trim($_post['phone']))) { $haserror = true; } else { $phone = trim($_post['phone']); } //check make sure subject field not empty if(trim($_post['subject']) == '') { $haserror = true; } else { $subject = trim($_post['subject']); } //check make sure comments entered if(trim($_post['message']) == '') { $haserror = true; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_post['message'])); } else { $comments = trim($_post['message']); } } //if there no error, send email if(!isset($haserror)) { $emailto = 'myemail@gmail.com'; //put own email address here $body = "<strong>name:</strong> $name <br><br><strong>email:</strong> $email <br><br><strong>contact:</strong> $phone <br><br><strong>subject:</strong> $subject <br><br><strong>message:</strong><br><br> $comments"; $headers = 'from: ucorp online form <'.$emailto.'>' . "\r\n" . 'reply-to: ' . $email . "\r\n"; $headers .= 'mime-version: 1.0' . "\r\n"; $headers .= 'content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($emailto, $subject, $body, $headers); $emailsent = true; } ?>
you're looking nl2br()
. apply after setting value $comments
:
if(trim($_post['message']) == '') { $haserror = true; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_post['message'])); } else { $comments = trim($_post['message']); } $comments = nl2br($comments); }
Comments
Post a Comment