How to fix dtheatre’s FormMail.php v5.0 form variables

Well, if you’re here you most likey are not getting any data from your FormMail script in the email you received. The problem is that dthetre’s script expects register_globals to be turned on. Since PHP4, most installations have register_globals turned off. This means your script will not work unless the feature is enabled. Most hosts are not likely to enable this feature (we’re one of them).

So here’s a quick workaround for the script. Add this code right after the header section of the script (before “// for ultimate security, use this instead of using the form”).

CODE UPDATED – SEE BELOW

//fix old register_globals style of form variable reference
$formvars = (isset($_POST)) ? $_POST : $HTTP_POST_VARS;
  foreach ($formvars as $key => $value) {
    $$key = $value;
  }
//older versions of php should work fine with or without the code above

There is apparently an issue with the form data being emailed twice. I will add another post to cover that when I get around to fixing it LOL.

***UPDATE***

While the code above fixed the register_globals problem, it did not fix the $HTTP_POST_VARS references. Here is the modified code.

// use $_POST instead of $HTTP_POST_VARS if it is available
if (isset($_POST)) $HTTP_POST_VARS = $_POST;
foreach ($HTTP_POST_VARS as $key => $value) {
	//fix old register_globals style of form variable reference
	$$key = $value;
}

Feel free to comment 🙂

// use $_POST instead of $HTTP_POST_VARS if it is available
if (isset($_POST)) {
$HTTP_POST_VARS = $_POST;
foreach ($HTTP_POST_VARS as $key => $value) {
//fix old register_globals style of form variable reference
$$key = $value;
}
}

One thought on “How to fix dtheatre’s FormMail.php v5.0 form variables

  1. juan

    Hi Robert, indeed yes, your updates (both) worked perfect, now form content is being received sucessfully.

    Thank you for your help and taking the time to explaining… cheers!

    Juan

    Reply

Leave a Reply to juan Cancel reply

Your email address will not be published. Required fields are marked *