I have a form that displays an error message that reads
Warning: Invalid argument supplied for foreach() in /home/content/d/a/b/dabody123/html/mailer.php on line 14
Warning: Cannot modify header information - headers already sent by (output started at /home/content/d/a/b/dabody123/html/mailer.php:14) in /home/content/d/a/b/dabody123/html/mailer.php on line 21
I know it's because I am trying redirect it to the index.php page. I just need to know how to modify the mailer.php file to get it to work. Here is the entire code.
<?php
if(isset($_POST['submit'])) {
$to = "demetriusmcclain@yahoo.com";
$subject = "Contact Form";
$fname_field = $_POST['firstname'];
$lname_field = $_POST['lastname'];
$email_field = $_POST['email'];
$country = $_POST['country'];
$business = $_POST['business'];
$products = $_POST['products'];
$distributor = $_POST['distributor'];
$message = $_POST['message'];
$body = "From: firstname: $fname_field\n lastname: $lname_field\n E-Mail: $email_field\n country: $country\n business: $business\n products: $products\n distributor: $distributor\n Message:\n $message";
header ('Location: http://www.dabodyshop.com/index.php');
exit ();
//echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
//echo "your form is incomplete";
}
?>
PHP form redirect
Moderator: General Moderators
Re: PHP form redirect
First you are calling mail() function before header location, which will not execute. Also there is not foreach statement in the code, from where you are getting this error.