0

okey i have upload my site everything works just fine except my contact form
here's my code

FYI - Im very new to the php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php

    $user_name = $_POST["NameBox"];
    $user_contact = null;
    $user_contact=$_POST["ContactBox"];
    $comment = $_POST["msgbox"];

    if($user_contact==null)
    {
        $user_contact = "Not provided";

    }


    $to = "mymail@domain.com";
     $subject = "Message From Web";
     $body = "Contact name is = $user_name | Contact number is = $user_contact | user comment is = $comment";

     mail($to, $subject, $body);

     header( 'Location:http://www.masconsolidated.com/confirmation.html');


?>
</body>
</html>

when i submit the form im getiing a error like

Warning: Cannot modify header information - headers already sent by (output started at /home/masconso/public_html/processData.php:10) in /home/masconso/public_html/processData.php on line 30

i can't figure it out..please help me (sample code will be better)
thanks

2
Contributors
4
Replies
7
Views
4 Years
Discussion Span
Last Post by istore221
0

You can't send headers after output (html, whitespace, php-derived html, php errors etc).

Try this:

<?php
    $user_name = $_POST["NameBox"];
    $user_contact = null;
    $user_contact=$_POST["ContactBox"];
    $comment = $_POST["msgbox"];
    if($user_contact==null)
    {
        $user_contact = "Not provided";
    }
    $to = "mymail@domain.com";
     $subject = "Message From Web";
     $body = "Contact name is = $user_name | Contact number is = $user_contact | user comment is = $comment";
     mail($to, $subject, $body);
     header( 'Location:http://www.masconsolidated.com/confirmation.html');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>

I can't see why you've got html here anyway. If you redirect, you don't see the page. Also - you may want to validate post input.

0

okey i have put only this lines for my php code

<?php
    $user_name = $_POST["NameBox"];
    $user_contact = null;
    $user_contact=$_POST["ContactBox"];
    $comment = $_POST["msgbox"];    
    if($user_contact==null)
    {
        $user_contact = "Not provided";
    }   
    $to = "mymail@domain.com";
    $subject = "Message From Web";
    $body = "Contact name is = $user_name | Contact number is = $user_contact | user comment is = $comment";
    mail($to, $subject, $body); 
    header("Location:confirmation.html");    
?>

is it necessary to put
header("Location:confirmation.html");
exit(); //at the end

0

It's good practice to do so.

If this solves your problem - mark it solved. :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.