Jump to content

Form problem


ninedoors

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.