0

I keep getting the warning "Warning: Cannot modify header information - headers already sent by (output started at /home/camelarc/public_html/contactform.php:11) in /home/camelarc/public_html/contactform.php on line 33"
The warning occurs after i fill out a form on my website and press submit. The warning appears, but the php file still sends an email to the specified account.

The php file is as follows:

<?php
if(isset($_POST['submit'])) {
$to="customerservice@camelarches.com";
$subject="Customer Feedback."; 
// data the visitor provided
$name_field=filter_var($_POST['name']);
$address_field=filter_var($_POST['address']);
$city_field=filter_var($_POST['city']);
$state_field=filter_var($_POST['state']);
$zip_field=filter_var($_POST['zip']);
$telephone_field=filter_var($_POST['telephone']);
$email_field=filter_var($_POST['email']);
$comment=filter_var($_POST['comment']);
//constructing the message
$body="From: $name_field\n\n E-Mail: $email_field\n\n Address: $address_field\n\n City: $city_field\n\n State: $state_field\n\n Zip: $zip_field\n\n Telephone: $telephone_field\n\n Message:\n\n $comment";
mail($to, $subject, $body); 
// redirect to confirmation
header('location:http://www.camelarches.com/');
exit;
}else{
// handle the error somehow
}
?>

I would really appreciate it if anyone could help me solve my problem. The warning occurs after i fill out a form on my website and press submit. The warning appears, but the php file still sends an email to the specified account.

3
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by senthilvignesh
0

Is there any HTML code before your php tag? No html or any other output can be sent before header() function (not even a space - check for those).

0

Yes, but is there must be some html output before calling the file above. Can you post the file that calls the above php code.

0

There should be an empty space or echo statement which sends the header to the client. So your header redirect is not working. Remove empty space and echo statements before header redirect.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.