OK, this may be an elementary question, and hopefully there is a quick and easy resolution...
I have always had this issue and previously just dealt with it, but want to get it working the way it should be.
When I generate an email from within a PHP script that includes form input from a visitor, it always comes through as a single continual block of text, no matter how it is entered.
Is there a way to at least format it with line feeds for each carriage return they enter?
I run all form entry through a clean string function and then send it to a mail sender function included below.
Any suggestions would be greatly appreciated. And if there is a more up to date means of handling email sending that wouldn't hurt either... I've been using these functions for years.
Douglas
I thought that it may be the clean string function I use so I bypasse it temporarily.
this is the message as it is delivered
Message :
Testing without the cleanstring function. Thinking that maybe the linefeeds will at least be intact. testing.
and as it was entered in the textarea form field:
Testing without the cleanstring function.
Thinking that maybe the linefeeds will at least be intact.
testing.
// ***********************************************************************
// trim white space front and back / replace special characters/protect DB data
function cleanString($string){
trim(htmlentities(mysql_real_escape_string($string)));
return $string;
}//end function
//**********************************************
// Function to send emails
// call with email address / from address / subject / body of message
function mail_sender($to,$from,$subject,$message_body)
{
$message = "<html><head><title>".$sitename."</title></head><body>";
$message=$message.$message_body;
$message .= "</body></html>";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";// More headers
$headers .= "From: <".$from.">" . "\r\n"; // modified function to include $from
$message = wordwrap($message,70);
// Send email
mail($to,$subject,$message,$headers);
}
//***********************************************
And just in case it comes up as being needed, here is the form I am currently using.
<!-- CONTACT FORM -->
<form action="<?php print $_SERVER['PHP_SELF']; ?>" method="POST">
<label>Name<?php if ($name_error != ''){print ' - <b><font color="#FF0000">'.$name_error.'</font></b>';} ?></label>
<input class="span6" type="text" name="cf_name" value="<?php print $prev_cf_name; ?>"><br>
<label>E-Mail<?php if ($email_error != ''){print ' - <b><font color="#FF0000">'.$email_error.'</font></b>';} ?></label>
<input class="span6" type="text" name="cf_email" value="<?php print $prev_cf_email; ?>"><br>
<label>Phone<?php if ($phone_error != ''){print ' - <b><font color="#FF0000">'.$phone_error.'</font></b>';} ?></label>
<input class="span6" type="text" name="cf_phone" value="<?php print $prev_cf_phone; ?>"><br>
<label>Subject<?php if ($subject_error != ''){print ' - <b><font color="#FF0000">'.$subject_error.'</font></b>';} ?></label>
<input class="span6" type="text" name="cf_subject" value="<?php print $prev_cf_subject; ?>"><br>
<label>Message<?php if ($message_error != ''){print ' - <b><font color="#FF0000">'.$message_error.'</font></b>';} ?></label>
<textarea class="span8" name="cf_message" rows="5" cols="25"><?php print $prev_cf_message; ?></textarea><br>
<input type="hidden" name="subbed" value="y">
<label> </label><input class="btn btn-large btn-info" type="submit" name="submit" value="Send Message">
</form>
<!-- END CONTACT FORM -->