Jump to content

My form processes, but none of the information comes thru?


Lori De

Recommended Posts

here's my html form:

<form action="contact2.php" method="post" target="_self" id="contactform">

                <ol>

                  <li>

                    <label for="name2">Your Name <span class="red">*</span></label>

                    <input id="name2" name="name2" class="text" />

                  </li>

                  <li>

                    <label for="youremail">Your email <span class="red">*</span></label>

                    <input id="youremail" name="youremail" class="text" />

                  </li>

                  <li>

                    <label for="company2">Company</label>

                    <input id="company2" name="company2" class="text" />

                  </li>

                  <li>

                    <label for="subject2">Subject</label>

                    <input id="subject2" name="subject2" class="text" />

                  </li>

                  <li>

                    <label for="message2">Message <span class="red">*</span></label>

                    <textarea id="message2" name="message2" rows="6" cols="50"></textarea>

                  </li>

                  <li class="buttons">

                    <input type="image" name="imageField" id="imageField" src="images/send.gif" />

                  </li>

                </ol>

              </form>

 

Here's my php code:

 

<?PHP

global $_POST;

$name = $_POST["name2"];

$youremail = $_POST["youremail"];

$company = $_POST["company2"];

$subject = $_POST["subject2"];

$message = $_POST["message2"];

 

$to = "[email protected]";

$subject = "Form Submission";

$headers = "From: $youremail\n";

 

$message = "A visitor to your site has filled out the following information.\n

Name: $name2

Email Address: $youremail

Company: $company2

Subject: $subject2

Message: $message2";

 

if (preg_match(' /[\r\n,;\'"]/ ', $_POST['youremail'])) {

  exit('Invalid Email Address');

}

else {

mail($to,$subject,$message,$headers);

}

 

 

?>

Remove the following line of code -

 

global $_POST;

 

A) Never use the global keyword, ever.

 

B) Php has got a built-in 'got ya' for you when you use global with one of the super global arrays ($_POST, $_GET, $_SESSION, ...). It creates a whole new array that is empty because it is not tied to the actual super global array.

Notice each of these post values are turned into variables.

$name = $_POST["name2"];
$youremail = $_POST["youremail"];
$company = $_POST["company2"];
$subject = $_POST["subject2"];
$message2 = $_POST["message2"];

Make sure these are the same variables you are using for your message.

$message = "A visitor to your site has filled out the following information.\n
Name: $name
Email Address: $youremail
Company: $company
Subject: $subject
Message: $message2"

I would then wrap all the php inside a posted value IF condition (usually submit) but in this case the name you're using is imageField.

 

<?PHP
IF (isset($_POST['mageField'])){
$name = $_POST["name2"];
$youremail = $_POST["youremail"];
$company = $_POST["company2"];
$subject = $_POST["subject2"];
$message = $_POST["message2"];

$to = "[email protected]";
$subject = "Form Submission";
$headers = "From: $youremail\n";

$message = "A visitor to your site has filled out the following information.\n
Name: $name
Email Address: $youremail
Company: $company
Subject: $subject
Message: $message2";

if (preg_match(' /[\r\n,;\'"]/ ', $_POST['youremail'])) {
  exit('Invalid Email Address');
}
else {
mail($to,$subject,$message,$headers);
}

}//END Bracket for IF (isset($_POST['mageField'])){
?>

 

Hey I may not have everything 100% here but I hope you get the idea.

 

I was on my way out the door when I wrote that last message.  Speaking of message, make sure the variable $message2 is the correct one used.  My last post should have said.

<?PHP
IF (isset($_POST['mageField'])){
$name = $_POST["name2"];
$youremail = $_POST["youremail"];
$company = $_POST["company2"];
$subject = $_POST["subject2"];
$message2 = $_POST["message2"];

$to = "[email protected]";
$subject = "Form Submission";
$headers = "From: $youremail\n";

$message = "A visitor to your site has filled out the following information.\n
Name: $name
Email Address: $youremail
Company: $company
Subject: $subject
Message: $message2";

if (preg_match(' /[\r\n,;\'"]/ ', $_POST['youremail'])) {
  exit('Invalid Email Address');
}
else {
mail($to,$subject,$message,$headers);
}

}//END Bracket for IF (isset($_POST['mageField'])){
?>

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.