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  = 'nrleigh@example.com';

// 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  = 'nrleigh@example.com';

// 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.