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.

Recommended Answers

All 4 Replies

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).

No, this is an external php file that i am calling from my website

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.