PHP form redirect

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
4mula_D
Forum Newbie
Posts: 1
Joined: Mon Feb 01, 2010 12:27 am

PHP form redirect

Post by 4mula_D »

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";
}
?>
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: PHP form redirect

Post by pbs »

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.
Post Reply