Jump to content

i have a form that is sending back a "Cannot modify header information"


studentofstone

Recommended Posts

Cannot modify header information - headers already sent by (output started at )  on line 179

I labeled 179 its at the bottom.

I understand this means its already generating the html but not how or where.  A solution would of course be nice but if some one could tell me even how to figure it out it would be great.

 

<?php

if(isset($_POST['email'])) {
   



// EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "test@test.com";
    $email_subject = "$mile";
    
     
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
    
     /*"trail_section_mile", float dash
    "trail_section_name", #9()alphanumeric
    "name",
    "date"auto date
    "email",same
    "telephone" same
    "trail_condition" no validation just sanitize size limit
    "attention_area"   no validation just sanitize size limit
    "under_20"          no validation just sanitize size limit
    "_20_54"          no validation just sanitize size limit
    "_55_over"          no validation just sanitize size limit
    */
if(!isset($_POST['trail_section_mile']) ) {
        died('1');      
    } 
    if(!isset($_POST['trail_section_name']) ) {
        died('2');      
    }
    if(!isset($_POST['name']) ) {
        died('3');      
    } 
    if(!isset($_POST['email']) ) {
        died('4');      
    }
    if(!isset($_POST['telephone']) ) {
        died('5');      
    } 
    if(!isset($_POST['trail_condition']) ) {
        died('6');   
    }
       if(!isset($_POST['attention_area']) ) {
        died('7');   
    }
    if(!isset($_POST['under_20']) ) {
        died('8');      
    } 
    if(!isset($_POST['_20_54']) ) {
        died('9');      
    }
    if(!isset($_POST['_55_over']) ) {
        died('0');      
    } 
   
      if(!isset($_POST['total_hours']) ) {
        died('011');      
    }
    
    //comments field is a honeypot
    
      require ('Validate.php');
$email = $_REQUEST['email'];
$validate = new Validate();
if (!Validate::email($email, array('check_domain' => true, 'use_rfc822' =>true))) {
  echo "Invalid email";
}
      
    
    $trail_section_mile = $_POST['trail_section_mile']; // required
    $trail_section_name = $_POST['trail_section_name']; // required
   $name = $_POST['name']; // required
   $email = $_POST['email']; // required
   $telephone = $_POST['telephone']; // required
   $trail_condition = $_POST['trail_condition']; // required
    $attention_area = $_POST['attention_area']; // required
   $under_20 = $_POST['under_20'];
   $_20_54 = $_POST['_20_54'];
   $_55_over = $_POST['_55_over'];
   $_55_over = $_POST['total_hours'];
    // required

if (preg_match('/[\d\D\b\B\s\S]/', $comments)) {
    echo "nope";
}
   
if (!preg_match("/([\w\.\#\-\,]{1,30})+/", $trail_section_mile)) 
{echo "please enter the section mile markers again only numbers, decimals dashes and # are aloud";
}

if (!preg_match("/[a-z'-]+/", $trail_section_name)) {
    echo "Try your last name again.";
}

if (!preg_match("/[a-z'-]+/", $name)) {   
    echo "please re-type your address.";
}

if (!preg_match("/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/i", $telephone))
{
    echo "Something is wrong with the phone number you intered. Please enter your area code first then ther rest of tyour number.";
}

   
if (( preg_match( "/[\r\n]/", $first_name ) || 
preg_match( "/[\r\n]/", $email ) || 
preg_match( "/[\r\n]/", $last_name) ) || 
preg_match( "/[\r\n]/", $state)) {

   echo "nope";

}
  
    $trail_section_mile = strip_tags($trail_section_mile);
    $trail_section_name = strip_tags($trail_section_name);
   $name  =strip_tags($name);
   $email = strip_tags($email);
   $telephone = strip_tags($telephone);
   $trail_condition = strip_tags($trail_condition);
    $attention_area = strip_tags($attention_area);
    $under_20 = strip_tags($under_20);
   $_20_54 = strip_tags($_20_54);
   $_55_over = strip_tags($_55_over);
    $total_hours = strip_tags($total_hours);
   
   
   $trail_section_mile = htmlspecialchars($trail_section_mile);
    $trail_section_name = htmlspecialchars($trail_section_name);
   $name = htmlspecialchars($name);
   $email = htmlspecialchars($email);
   $telephone = htmlspecialchars($telephone);
   $trail_condition = htmlspecialchars($trail_condition);
    $attention_area = htmlspecialchars($attention_area);
    $under_20 = htmlspecialchars($under_20);
   $under_20 = htmlspecialchars($_20_54);
   $_55_over = htmlspecialchars($_55_over);
    $total_hours = htmlspecialchars($total_hours);
    
   
  
    $email_message = "Form details below.\n\n";
       $email_message = date("m/d/Y") . "\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
     
    $email_message .= "Trail Section Mile Markers: ".clean_string($trail_section_mile)."\n";
    $email_message .= "Trail Section Name : ".clean_string($trail_section_name)."\n";
   $email_message .= "Reported by: ".clean_string($name)."\n";
   $email_message .= "Email Address: ".clean_string($email)."\n";
   $email_message .= "Telephone Number: ".clean_string($telephone)."\n";
   $email_message .= "General Trail Condition : ".clean_string($trail_condition)."\n";
    $email_message .= "Mile #/Problem/Suggested Improvements: ".clean_string($attention_area)."\n";
    $email_message .= "Volunteers Under Age 20 #Males/#Females/Ethnicity/Name: ".clean_string($under_20)."\n";
    $email_message .= "   
Volunteers Ages 20 to 54 #Males/#Females/Ethnicity/Name: ".clean_string($_20_54)."\n";
        $email_message .= "Volunteers Age 55+ #Males/#Females/Ethnicity/Name: ".clean_string($_55_over)."\n";
    $email_message .= "Total Volunteer Hours: ".clean_string($total_hours)."\n";

   
     $about ="Maintenance Report from" .$name. "/n";
     
// create email headers
$headers = 'Subject : '.$about."/r/n"
.'From: '.$email."\r\n"
.'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
header("Location: oht/maintenance/maintenance-report/thank-you/");                              //line 179
@mail($email_to, $email_subject, $email_message, $headers); 
?>

<?php
}
?>

 

MOD EDIT:

 . . . 

BBCode tags added.

Link to comment
Share on other sites

First apologies about not nesting. I typed


instead of

.

Yes I read it but it doesn't make sense to me for my application of the header, or I am misunderstanding it.

The code is sending the form data as an email. How would a meta tag work here to redirect?

$headers = 'Subject : '.$about."/r/n"
.'From: '.$email."\r\n"
.'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
header("Location: oht/maintenance/maintenance-report/thank-you/");                              //line 179
@mail($email_to, $email_subject, $email_message, $headers); 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.