Hello,
I am trying to do a simple form (text fields only). The users enter, submit, then there is a confirmation page and information is sent to an email. When 'submit' is clicked there is no information returned from the $_POST variable. Here is the code:

$to="MyEmail@MyAddress.com";
$subject=$_POST['course'];
echo "<p>Thank you" $_POST['name'] "!<br>";
echo "Your assignment for" $_POST['course'] "has been submitted.";
//mail string to send to email
$msg = "NAME: " $_POST['name'];
$msg .= "LICENSE NO: " $_POST['license'];
$msg .= "EMAIL: " $_POST['email'];
$msg .= "DATE: " $_POST['mydate'];
$msg .= "QUESTION 1: " $_POST['q1'];
$msg .= "QUESTION 2:" $_POST['q2'];
$headers ="FROM: " $_POST['email'];
//set up mail
mail($to,$subject,$msg,$headers);
?>

The form action and textfields values are correct. I get the "text" but nothing from the html form. Now, my remote host supports php, so thats not an issue. I am working in DWMX 2003, PHP 5.0.2, on WinXP pro.
I am getting very frustrated and could really use some expertise.
Thanks.

Dani AI

Generated

Two immediate, common causes explain the behavior you describe: a PHP parse/syntax problem when joining strings and variables, and testing the script outside a PHP-capable server (so $_POST never populates). supplied the original snippet and was right to urge a POST-check, but the best fixes are (a) validate that PHP is actually running and (b) correct how you build strings and headers.

Quick checklist to debug:

  • Access the page via HTTP ( or your remote URL), not file://. Dreamweaver previews will not run PHP unless they use a local server.
  • Ensure every input uses a name attribute (e.g., name="email") — ids alone do not create $_POST keys.
  • Temporarily dump the incoming data to confirm what arrives: var_dump($_POST); or write it to a log.
  • Turn on error display or check server error logs so parse errors are visible.

Minimal safe patterns to follow:

  • Test request method (preferred) with $_SERVER['REQUEST_METHOD'] === 'POST'.
  • Concatenate strings with . and escape output with htmlspecialchars() before echoing.
  • Validate $_POST['email'] with filter_var(..., FILTER_VALIDATE_EMAIL) before using it in a From: header, and refuse or sanitize inputs to prevent header injection.
  • When building headers, use CRLF \r\n as required by the mail function and supply a fallback From address if the user email is invalid.

Authoritative references:

If parse errors persist, enable errors or upload the script to a PHP-enabled host and re-test; once PHP runs, a simple var_dump($_POST) will immediately show whether the form actually submitted values.

Recommended Answers

All 2 Replies

Oops, this is a bad way to start out...I have posted this in the wrong forum.

Whenever you use _POST make sure you preface the logic with a statement like:

if (isset(_POST) {
.
.
.
}

Now in your HTML form make sure you specify POST as the method. Generally speaking as long as your server is PHP enabled and the action statement in HTML points to your PHP script and the method is correct you should be good to go.

Let me know if you would like a simple sample of a HTML page that calls a PHP script.

Hello,

I am trying to do a simple form (text fields only). The users enter, submit, then there is a confirmation page and information is sent to an email. When 'submit' is clicked there is no information returned from the $_POST variable. Here is the code:

$to="MyEmail@MyAddress.com";
$subject=$_POST['course'];
echo "<p>Thank you" $_POST['name'] "!<br>";
echo "Your assignment for" $_POST['course'] "has been submitted.";
//mail string to send to email
$msg = "NAME: " $_POST['name'];
$msg .= "LICENSE NO: " $_POST['license'];
$msg .= "EMAIL: " $_POST['email'];
$msg .= "DATE: " $_POST['mydate'];
$msg .= "QUESTION 1: " $_POST['q1'];
$msg .= "QUESTION 2:" $_POST['q2'];
$headers ="FROM: " $_POST['email'];
//set up mail
mail($to,$subject,$msg,$headers);
?>

The form action and textfields values are correct. I get the "text" but nothing from the html form. Now, my remote host supports php, so thats not an issue. I am working in DWMX 2003, PHP 5.0.2, on WinXP pro.
I am getting very frustrated and could really use some expertise.
Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.