Dennisg Posted November 21, 2009 Share Posted November 21, 2009 Hi, I would greatly appreciate some help? I am brand new to PHP and have been searching and editing code ALL day :shrug:yet I still cannot find the reason for this error in my Sendmail.php file: Warning: Cannot modify header information - headers already sent by (output started at /home/appleis/public_html/sendmail.php:3) in /home/appleis/public_html/sendmail.php on line 48 My only thought is it may be related to the function "show_error" which has a html section and may affect the browser cache. I don't know how to fix that? The above error is occurring when all test data entered is in the correct style and fields validate. If I deliberately leave out a valid field, my check controls and show_error work properly yet as soon as they are fixed the next submit casues the heading error statement. I am using a html form & I know all my fields in html are correct. Any help is much appreciated, Dennis My Sendmail.php code is as follows, the bad code line is in red: <head> <style type="text/css"> .style1 { background-color: C7AEC7; } </style> </head> <?php /* Set e-mail recipient */ $myemail = "myname@mydomain.com.au"; /* Instead of captcha use this access code, set in my html form for the euser to enter.*/ if (strtolower($_POST['accesscode']) != 'apple') {die('Wrong access code, Use Back Browser button and re-enter code');} /* Check all form inputs using check_input function */ $firstname = check_input($_REQUEST['first_name'], "Please Enter First Name with NO spaces or numbers. Please press the BACK button in your browser and try again.") ; $lastname = check_input($_REQUEST['last_name'], "Please Enter Last Name with NO spaces or numbers. Please press the BACK button in your browser and try again.") ; $street = $_REQUEST['street_no'] ; $suburb = check_input($_REQUEST['suburb']) ; $state = check_input($_REQUEST['state']) ; $pcode = $_REQUEST['pcode'] ; $country = check_input($_REQUEST['ctry']) ; $phone = check_input($_REQUEST['phone_no'], "Please Enter a contact Phone number. Please press the BACK button in your browser and try again.") ; $email = check_input($_REQUEST['email'],"Please Re- Enter your Email Address, ensuring you check the format. Please press the BACK button in your browser and try again.") ; $cottage = $_REQUEST['cottage'] ; $arr_day = check_input($_REQUEST['arr_day'], "Please Enter a valid Arrival day. Please press the BACK button in your browser and try again.") ; $arr_date = check_input($_REQUEST['arr_date'], "Please Enter a valid Arrival date. Please press the BACK button in your browser and try again.") ; $arr_month = check_input($_REQUEST['arr_month'], "Please Enter a valid Arrival month. Please press the BACK button in your browser and try again.") ; $arr_year = check_input($_REQUEST['arr_year'], "Please Enter a valid Arrival year. Please press the BACK button in your browser and try again.") ; $dep_day = check_input($_REQUEST['dep_day'], "Please Enter a valid Departure day. Please press the BACK button in your browser and try again.") ; $dep_date = check_input($_REQUEST['dep_date'], "Please Enter a valid Departure date. Please press the BACK button in your browser and try again.") ; $dep_month = check_input($_REQUEST['dep_month'], "Please Enter a valid Departure month. Please press the BACK button in your browser and try again.") ; $dep_year = check_input($_REQUEST['dep_year'], "Please Enter a valid Departure year. Please press the BACK button in your browser and try again.") ; $adults = check_input($_REQUEST['adult_guests_num'], "Please Enter a number of Adult Guests. Please press the BACK button in your browser and try again.") ; $children = $_REQUEST['child_guests_num'] ; $message = check_input($_REQUEST['additional_info']) ; /* Check if e-mail is valid structure, if not show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("E-mail address not valid"); } /* Send the message using mail() function */ mail( $myemail, "Enquiry for Accommodation", "From: $email", "$firstname $lastname, \n$street, $suburb, \n$state. $pcode \nCountry: $country \nPh: $phone \nPreferred Cottage: $cottage\n \nArrival Date: $arr_day $arr_date/$arr_month/$arr_year\n \nDepart Date: $dep_day $dep_date/$dep_month/$dep_year \nAdults: $adults\n \nChildren: $children\n \nMessage: $message\n" ); /* Redirect visitor to the thank you page */ header("Location: http://www.mydomain.com.au/enquiry_thankyou.html"); /* Prepare autoresponder subject */ $respond_subject = "Thank you for contacting us."; /* Prepare autoresponder message */ $respond_message = "Hello $firstname, Thank you for the accommodation enquiry. Your requested stay: $arr_date/$arr_month/$arr_year to $dep_date/$dep_month/$dep_year Enquiry Name: $lastname Number of Guests: Adults - $adults, Children (under 12yrs) - $children I will respond to you within 24 hours. Regards, Julie, Our business & domain "; /* Send the message using mail() function */ mail($email, $respond_subject, $respond_message); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; }function show_error($myError) { ?> <html> <body> <b><span class="style1"> Cottages - Enquiry FORM<br></span><br>Please correct the following error:<br></b><br> <?php echo $myError; ?> </body> </html> <?php exit(); } /* this form is working and provides all functions */ ?> Quote Link to comment https://forums.phpfreaks.com/topic/182372-sendmailphp-heading-error-following-check_input/ Share on other sites More sharing options...
mikesta707 Posted November 21, 2009 Share Posted November 21, 2009 you can't have any html before the header is sent. if you look at the error it says output started on line 3. check out that line and the lines around. Also, put your code in code tags please Quote Link to comment https://forums.phpfreaks.com/topic/182372-sendmailphp-heading-error-following-check_input/#findComment-962390 Share on other sites More sharing options...
Dennisg Posted November 21, 2009 Author Share Posted November 21, 2009 Hi Mike, Many thanks for the prompt reply - YES I did not understand the error begun at line 3. All fixed when I deleted the style code in the <head>, any issues then disappeared. -------------------------------------- Re yr comment "put your code in code tags please" - Can you explain further? I am not aware of the issue? I set up this php file using the help from "thesitewizard" and "myphpform" and the code is exactly as they represented. Cheers Dennis Quote Link to comment https://forums.phpfreaks.com/topic/182372-sendmailphp-heading-error-following-check_input/#findComment-962395 Share on other sites More sharing options...
mikesta707 Posted November 21, 2009 Share Posted November 21, 2009 Oh i mean on the forums. either [code] [/code] Also there are php tags for specifically php [code=php:0] [/code] Quote Link to comment https://forums.phpfreaks.com/topic/182372-sendmailphp-heading-error-following-check_input/#findComment-962397 Share on other sites More sharing options...
cags Posted November 21, 2009 Share Posted November 21, 2009 and . There's also [nobbc] tags which come in helpful mikesta707. Quote Link to comment https://forums.phpfreaks.com/topic/182372-sendmailphp-heading-error-following-check_input/#findComment-962542 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.