ninedoors Posted May 19, 2008 Share Posted May 19, 2008 I am getting a weird problem when I try to send an email through my contact form. I have my form action set to sendmail.php script which uses php mail function and then redirects the user to a success page. But I tested it and I keep getting a HTTP 404 error on my sendmail.php script. It is on the server I can see it. This is what my script looks like. <?php //get info from form $name = $_POST['name']; $email = $_POST['email']; $themessage = $_POST['message']; // multiple recipients $to = '[email protected]'; // subject $subject = 'From website contact page'; // message $message = $themessage; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: Mike <' . $to . '>' . "\r\n"; $headers .= 'From: ' . $name . ' <' . $email . '>' . "\r\n"; // Mail it mail($to, $subject, $message, $headers); header("Location: '/index.php'"); ?> No when I add the html tags and stuff to it I get an error saying "can't modify headers on line 36 already sent on line 9". So when i get this error this is what my script looks like: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Barrie Mens Hockey League</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php //line 9 //get info from form $name = $_POST['name']; $email = $_POST['email']; $themessage = $_POST['message']; // multiple recipients $to = '[email protected]'; // subject $subject = 'From website contact page'; // message $message = $themessage; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: Mike <' . $to . '>' . "\r\n"; $headers .= 'From: ' . $name . ' <' . $email . '>' . "\r\n"; // Mail it mail($to, $subject, $message, $headers); header("Location: '/index.php'"); //line 36 ?> </body> </html> Any thoughts on a solution or what the problem is. I want to know why the server can't find the script when I don't have the html tags and stuff in it? Thanks Link to comment https://forums.phpfreaks.com/topic/106322-form-problem/ Share on other sites More sharing options...
DeanWhitehouse Posted May 19, 2008 Share Posted May 19, 2008 header's have to be sent before any HTML, and if it is a 404 error, then the filename you are looking for is either wrong or not there. Check whether it is in the same folder. Link to comment https://forums.phpfreaks.com/topic/106322-form-problem/#findComment-544894 Share on other sites More sharing options...
micmania1 Posted May 19, 2008 Share Posted May 19, 2008 header("Location: index.php"); //line 36 remove the single quotes and forwards slash. Link to comment https://forums.phpfreaks.com/topic/106322-form-problem/#findComment-545023 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.