gshaeffer Posted August 7, 2007 Share Posted August 7, 2007 A "\n" produces a line feed or new line when put in a string. However, it doesn't always work and I can not figure out why. I have done this twice now and I have no idea what makes it happen. Let me show you some code and you see if you can figure it out. Two files, billsupport.html and web_form_light.php. The problem is in the send_mail function. <?php error_reporting(E_ALL ^ E_NOTICE); require_once("web_form_light.php"); //Init a new webform $myform = new webform("billsupport.html", "post"); //Create new form fields $recipients = "email@something.com"; $sitename = "something.com"; $subject = "Bill Support from $sitename"; $myform->new_text("First Name", "first_name", $_POST['first_name'], "35", REQUIRED); $myform->new_text("Last Name", "last_name", $_POST['last_name'], "35", REQUIRED); $myform->new_text("Email", "email", $_POST['email'], "35", REQUIRED, EMAIL); $myform->new_text("City", "city", $_POST['city'], "21"); $myform->new_text("Day Phone", "day_phone", $_POST['day_phone'], "13", REQUIRED, PHONE); $myform->new_textarea("Why favor?", "whyfavor", $_POST['whyfavor'], "40", "5"); $myform->new_radio("Have you had problems with your computer?", "problems_", $_POST['problems_']); $myform->new_radio("Would you be willing to testify at a public hearing in the future?", "testify", $_POST['testify']); $myform->new_submit("submit", "Send Form Now"); $myform->new_reset("reset", " Clear Form "); if (isset($_POST['submit'])) { if ($myform->has_errors()) { $display_form = true; } else { if ($myform->send_mail($recipients, $subject, $sitename)) { header('Location: billsupport-thanks.html'); exit; } else { echo "There was a problem sending the data through email."; } } } else { $display_form = true; } ?> This is the send_mail function that formats a message. The "\n" works most of the time, but every once in a while it ignors the new line and puts a space instead. <?php function send_mail($recipients, $subject, $sitename) { $retval = false; $headers = "From: $sitename <info@$sitename>\n"; $message_body .= "Date: " . date("m/d/Y") . "\n"; $message_body .= "Time: " . date("h:i:sA") . " (Central Time Zone)\n"; foreach ($this->fields as $key => $value) { if ((is_a($this->fields["$key"], text_input)) || (is_a($this->fields["$key"], select_input) ) || (is_a($this->fields["$key"], checkbox_input) ) || (is_a($this->fields["$key"], radio_input) ) || (is_a($this->fields["$key"], textarea_input)) ) { $message_body .= $value->label . ": " . $value->value . "\n"; } else { } } if (mail($recipients, $subject, $message_body, $headers)) { $retval = true; } return $retval; } ?> Any help would be appreciated. If you need more information, contact me through the forum. Thanks, gshaeffer Quote Link to comment https://forums.phpfreaks.com/topic/63735-stumped-on-this-intermittent-n-problem/ Share on other sites More sharing options...
drewbee Posted August 7, 2007 Share Posted August 7, 2007 The only thing I can think of is maybe the way the Email Program is interpreting it. Is the intent of the receiver to use HTML or plain text email? If they receive html, it could very well need a <br/> instead of a \n to space it down. Quote Link to comment https://forums.phpfreaks.com/topic/63735-stumped-on-this-intermittent-n-problem/#findComment-317614 Share on other sites More sharing options...
gshaeffer Posted August 7, 2007 Author Share Posted August 7, 2007 It is a plain text version of email. I actually thought about using HTML email, but that wasn't in the project requirements. Has anyone had this problem with the "\n" line feed escape sequence in php. Could it be some kind of character set throwing it off? I'm just taking crazy guesses now. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/63735-stumped-on-this-intermittent-n-problem/#findComment-317642 Share on other sites More sharing options...
drewbee Posted August 7, 2007 Share Posted August 7, 2007 Another thing I notice through your loop is taht you do have a else { } where nothing happens. Is it possible for your loop to actual enter the "else" part of the statement? If anything, make sure a echo "\n"; exists in the else { } part. See if that fixes what may cause your problem. Quote Link to comment https://forums.phpfreaks.com/topic/63735-stumped-on-this-intermittent-n-problem/#findComment-317693 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.