Jump to content

Php form email help!


jacrave

Recommended Posts

i am new to php, and its been 10 years since i touched the html or net with coding, and i am trying to post a form to our sql database but also email it so we know when we have a new registration, but when the email arrives it is blank, here is the code...

 

 

<?php     
    $email_to = "jacrave@gmail.com";
    $email_subject = "Your email subject line";
     
    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
     
    $email_message .= "First Name: ".($varFirst)."\n";
    $email_message .= "Last Name: ".($varLast)."\n";
    $email_message .= "Email: ".($varEmail)."\n";
    $email_message .= "Phone Number: ".($varPhone)."\n";
    $email_message .= "Address: ".($varAddress1)."\n";
    $email_message .= "City: ".($varCity)."\n";
    $email_message .= "State: ".($varState)."\n";
    $email_message .= "Zip: ".($varZip)."\n";
    $email_message .= "DL number: ".($varDlnum)."\n";
    $email_message .= "DL State: ".($varDlstate)."\n";
    $email_message .= "Gender: ".($varGender)."\n";
 
 
 
     
     
// create email headers
$headers = 'From: '.$varEmail."\r\n".
'Reply-To: '.$varEmail."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

 

any help would be greatly appricated! thanks in advance

Link to comment
Share on other sites

the subject line comes through and the body is as follows:

 

Form details below.

First Name: 
Last Name: 
Email: 
Phone Number: 
Address: 
City: 
State: 
Zip: 
DL number: 
DL State: 
Gender:

 

 

 the form poplulates but without the inputed data

Link to comment
Share on other sites

Here is the complete code...

 

 

 

<?php
if($_POST['formSubmit'] == "Submit") 
    {
$errorMessage = "";
 
if(empty($_POST['formFirst'])) 
        {
$errorMessage .= "<li>You forgot to enter a First Name!</li>";
}
if(empty($_POST['formLast'])) 
        {
$errorMessage .= "<li>You forgot to enter a Last Name!</li>";
}
if(empty($_POST['formPhone'])) 
        {
$errorMessage .= "<li>You forgot to enter a Phone Number!</li>";
}
if(empty($_POST['formEmail'])) 
        {
$errorMessage .= "<li>You forgot to enter a Email Address</li>";
}
if(empty($_POST['formAddress1']))
        {
$errorMessage .= "<li>You forgot to enter a Address!</li>";
}
if(empty($_POST['formCity'])) 
        {
$errorMessage .= "<li>You forgot to enter a City!</li>";
}
if(empty($_POST['formZip'])) 
        {
$errorMessage .= "<li>You forgot to enter a Zip Code!</li>";
}
if(empty($_POST['formDlnum'])) 
        {
$errorMessage .= "<li>You forgot to enter a Driver License Number!</li>";
}
if(empty($_POST['formGender'])) 
        {
$errorMessage .= "<li>You forgot to select your Gender!</li>";
}
if(empty($_POST['formDlstate'])) 
        {
$errorMessage .= "<li>You forgot to select your Driver License State!</li>";
}
if(empty($_POST['formState'])) 
        {
$errorMessage .= "<li>You forgot to select your State!</li>";
}
 
 
        $varFirst = $_POST['formFirst'];
$varLast = $_POST['formLast'];
$varEmail = $_POST['formEmail'];
$varPhone = $_POST['formPhone'];
$varAddress1 = $_POST['formAddress1'];
$varCity = $_POST['formCity'];
$varZip = $_POST['formZip'];
$varDlnum = $_POST['formDlnum'];
$varGender = $_POST['formGender'];
$varDlstate = $_POST['formDlstate'];
$varState = $_POST['formState'];
 
 
if(empty($errorMessage)) 
        {
$db = mysql_connect("XXX.XXX.XXX.XXX","XXXXXXXXX","XXXXXXXXX!!");
if(!$db) die("Error connecting to MySQL database.");
mysql_select_db("XXXXXXXXX" ,$db);
 
$sql = "INSERT INTO XXXXXXXXX (formFirst, formLast, formEmail, formPhone, formAddress1, formCity, formState, formZip, formDlnum, formDlstate, formGender) VALUES (".
PrepSQL($varFirst) . ", " .
PrepSQL($varLast) . ", " .
PrepSQL($varEmail) . ", " .
PrepSQL($varPhone) . "," .
PrepSQL($varAddress1) . ", " .
PrepSQL($varCity) . ", " .
PrepSQL($varState) . ", " .
PrepSQL($varZip) . ", " .
PrepSQL($varDlnum) . ", " .
PrepSQL($varDlstate) . ", " .
PrepSQL($varGender) . ")";
mysql_query($sql);
 
header("Location: thankyou.html");
exit();
}
}
            
    // function: PrepSQL()
    // use stripslashes and mysql_real_escape_string PHP functions
    // to sanitize a string for use in an SQL query
    //
    // also puts single quotes around the string
    //
    function PrepSQL($value)
    {
        // Stripslashes
        if(get_magic_quotes_gpc()) 
        {
            $value = stripslashes($value);
        }
 
        // Quote
        $value = "'" . mysql_real_escape_string($value) . "'";
 
        return($value);
    }
 
 
?>
 
<?php     
    $email_to = "jacrave@gmail.com";
    $email_subject = "MM Signup";
     
    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
     
    $email_message .= "First Name: ".($varFirst)."\n";
    $email_message .= "Last Name: ".($varLast)."\n";
    $email_message .= "Email: ".($varEmail)."\n";
    $email_message .= "Phone Number: ".($varPhone)."\n";
    $email_message .= "Address: ".($varAddress1)."\n";
    $email_message .= "City: ".($varCity)."\n";
    $email_message .= "State: ".($varState)."\n";
    $email_message .= "Zip: ".($varZip)."\n";
    $email_message .= "DL number: ".($varDlnum)."\n";
    $email_message .= "DL State: ".($varDlstate)."\n";
    $email_message .= "Gender: ".($varGender)."\n";
 
 
 
     
     
// create email headers
$headers = 'From: '.$varEmail."\r\n".
'Reply-To: '.$varEmail."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>
 
 
<html>
<head>
 
<style>
label,a 
{
font-family : Arial, Helvetica, sans-serif;
font-size : 12px; 
}
 
</style>
</head>
 
<body>
 
       <?php
   if(!empty($errorMessage)) 
   {
   echo("<p>There was an error with your form:</p>\n");
   echo("<ul>" . $errorMessage . "</ul>\n");
            }
        ?>
 
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
 
<p>
<label for='formFirst'>First Name?</label><br/>
<input type="text" name="formFirst" maxlength="50" value="<?=$varFirst;?>" />
          </p>  
           
            <p> 
                <label for='formLast'>Last Name?</label><br/>
   <input type="text" name="formLast" maxlength="50" value="<?=$varLast;?>" />
</p>
 
            <p> 
                <label for='formEmail'>Email Address?</label><br/>
 <input type="text" name="formEmail" maxlength="500" value="<?=$varEmail;?>" />
</p>
 
            <p> 
                <label for='formPhone'>Phone Number?</label><br/>
 <input type="text" name="formPhone" maxlength="500" value="<?=$varPhone;?>" />
</p>
 
<p>
 <label for='formAddress1'>Street Address?</label><br/>
 <input type="text" name="formAddress1" maxlength="500" value="<?=$varAddress1;?>" />
 </p>
                        
       <p>
<label for='formCity'>City?</label><br/>
   <input type="text" name="formCity" maxlength="50" value="<?=$varCity;?>" />
</p>
 
<p>
            <label for='formState'> State?</label><br/>
            <select name="formState">
<option selected value="">State...</option>
<option value="AL"<? if($varState=="AL") echo(" selected=\"selected\"");?>>Alabama</option>
<option value="AK"<? if($varState=="AK") echo(" selected=\"selected\"");?>>Alaska</option>
<option value="AZ"<? if($varState=="AZ") echo(" selected=\"selected\"");?>>Arizona</option>
<option value="AR"<? if($varState=="AR") echo(" selected=\"selected\"");?>>Arkansas</option>
<option value="CA"<? if($varState=="CA") echo(" selected=\"selected\"");?>>California</option>
<option value="CO"<? if($varState=="CO") echo(" selected=\"selected\"");?>>Colorado</option>
<option value="CT"<? if($varState=="CT") echo(" selected=\"selected\"");?>>Connecticut</option>
<option value="DE"<? if($varState=="DE") echo(" selected=\"selected\"");?>>Delaware</option>
<option value="FL"<? if($varState=="FL") echo(" selected=\"selected\"");?>>Florida</option>
<option value="GA"<? if($varState=="GA") echo(" selected=\"selected\"");?>>Georgia</option>
<option value="HI"<? if($varState=="HI") echo(" selected=\"selected\"");?>>Hawaii</option>
<option value="ID"<? if($varState=="ID") echo(" selected=\"selected\"");?>>Idaho</option>
<option value="IL"<? if($varState=="IL") echo(" selected=\"selected\"");?>>Illinois</option>
<option value="IN"<? if($varState=="IN") echo(" selected=\"selected\"");?>>Indiana</option>
<option value="IA"<? if($varState=="IA") echo(" selected=\"selected\"");?>>Iowa</option>
<option value="KS"<? if($varState=="KS") echo(" selected=\"selected\"");?>>Kansas</option>
<option value="KY"<? if($varState=="KY") echo(" selected=\"selected\"");?>>Kentucky</option>
<option value="LA"<? if($varState=="LA") echo(" selected=\"selected\"");?>>Louisiana</option>
<option value="ME"<? if($varState=="ME") echo(" selected=\"selected\"");?>>Maine</option>
<option value="MD"<? if($varState=="MD") echo(" selected=\"selected\"");?>>Maryland</option>
<option value="MA"<? if($varState=="MA") echo(" selected=\"selected\"");?>>Massachusetts</option>
<option value="MI"<? if($varState=="MI") echo(" selected=\"selected\"");?>>Michigan</option>
<option value="MN"<? if($varState=="MN") echo(" selected=\"selected\"");?>>Minnesota</option>
<option value="MS"<? if($varState=="MS") echo(" selected=\"selected\"");?>>Mississippi</option>
<option value="MO"<? if($varState=="MO") echo(" selected=\"selected\"");?>>Missouri</option>
<option value="MT"<? if($varState=="MT") echo(" selected=\"selected\"");?>>Montana</option>
<option value="NE"<? if($varState=="NE") echo(" selected=\"selected\"");?>>Nebraska</option>
<option value="NV"<? if($varState=="NV") echo(" selected=\"selected\"");?>>Nevada</option>
<option value="NH"<? if($varState=="NH") echo(" selected=\"selected\"");?>>New Hampshire</option>
<option value="NJ"<? if($varState=="NJ") echo(" selected=\"selected\"");?>>New Jersey</option>
<option value="NM"<? if($varState=="NM") echo(" selected=\"selected\"");?>>New Mexico</option>
<option value="NY"<? if($varState=="NY") echo(" selected=\"selected\"");?>>New York</option>
<option value="NC"<? if($varState=="NC") echo(" selected=\"selected\"");?>>North Carolina</option>
<option value="ND"<? if($varState=="ND") echo(" selected=\"selected\"");?>>North Dakota</option>
<option value="OH"<? if($varState=="OH") echo(" selected=\"selected\"");?>>Ohio</option>
<option value="OK"<? if($varState=="OK") echo(" selected=\"selected\"");?>>Oklahoma</option>
<option value="OR"<? if($varState=="OR") echo(" selected=\"selected\"");?>>Oregon</option>
<option value="PA"<? if($varState=="PA") echo(" selected=\"selected\"");?>>Pennsylvania</option>
<option value="RI"<? if($varState=="RI") echo(" selected=\"selected\"");?>>Rhode Island</option>
<option value="SC"<? if($varState=="SC") echo(" selected=\"selected\"");?>>South Carolina</option>
<option value="SD"<? if($varState=="SD") echo(" selected=\"selected\"");?>>South Dakota</option>
<option value="TN"<? if($varState=="TN") echo(" selected=\"selected\"");?>>Tennessee</option>
<option value="TX"<? if($varState=="TX") echo(" selected=\"selected\"");?>>Texas</option>
<option value="UT"<? if($varState=="UT") echo(" selected=\"selected\"");?>>Utah</option>
<option value="VT"<? if($varState=="VT") echo(" selected=\"selected\"");?>>Vermont</option>
<option value="VA"<? if($varState=="VA") echo(" selected=\"selected\"");?>>Virginia</option>
<option value="WA"<? if($varState=="WA") echo(" selected=\"selected\"");?>>Washington</option>
<option value="WV"<? if($varState=="WV") echo(" selected=\"selected\"");?>>West Virginia</option>
<option value="WI"<? if($varState=="WI") echo(" selected=\"selected\"");?>>Wisconsin</option>
<option value="WY"<? if($varState=="WY") echo(" selected=\"selected\"");?>>Wyoming</option>
</select>
          </p>
 
 
<p>
<label for='formZip'>Zip Code?</label><br/>
 <input type="text" name="formZip" maxlength="50" value="<?=$VarZip;?>" />
</p>
           
 
            <p> 
              <label for='formDlnum'>Driver License Number?</label>
                <br/>
 <input type="text" name="formDlnum" maxlength="50" value="<?=$varDlnum;?>" />
 </p>
 
 
                <label for='formDlstate'> State?</label><br/>
            <select name="formDlstate">
<option selected value="">State...</option>
<option value="AL"<? if($varDlstate=="AL") echo(" selected=\"selected\"");?>>Alabama</option>
<option value="AK"<? if($varDlstate=="AK") echo(" selected=\"selected\"");?>>Alaska</option>
<option value="AZ"<? if($varDlstate=="AZ") echo(" selected=\"selected\"");?>>Arizona</option>
<option value="AR"<? if($varDlstate=="AR") echo(" selected=\"selected\"");?>>Arkansas</option>
<option value="CA"<? if($varDlstate=="CA") echo(" selected=\"selected\"");?>>California</option>
<option value="CO"<? if($varDlstate=="CO") echo(" selected=\"selected\"");?>>Colorado</option>
<option value="CT"<? if($varDlstate=="CT") echo(" selected=\"selected\"");?>>Connecticut</option>
<option value="DE"<? if($varDlstate=="DE") echo(" selected=\"selected\"");?>>Delaware</option>
<option value="FL"<? if($varDlstate=="FL") echo(" selected=\"selected\"");?>>Florida</option>
<option value="GA"<? if($varDlstate=="GA") echo(" selected=\"selected\"");?>>Georgia</option>
<option value="HI"<? if($varDlstate=="HI") echo(" selected=\"selected\"");?>>Hawaii</option>
<option value="ID"<? if($varDlstate=="ID") echo(" selected=\"selected\"");?>>Idaho</option>
<option value="IL"<? if($varDlstate=="IL") echo(" selected=\"selected\"");?>>Illinois</option>
<option value="IN"<? if($varDlstate=="IN") echo(" selected=\"selected\"");?>>Indiana</option>
<option value="IA"<? if($varDlstate=="IA") echo(" selected=\"selected\"");?>>Iowa</option>
<option value="KS"<? if($varDlstate=="KS") echo(" selected=\"selected\"");?>>Kansas</option>
<option value="KY"<? if($varDlstate=="KY") echo(" selected=\"selected\"");?>>Kentucky</option>
<option value="LA"<? if($varDlstate=="LA") echo(" selected=\"selected\"");?>>Louisiana</option>
<option value="ME"<? if($varDlstate=="ME") echo(" selected=\"selected\"");?>>Maine</option>
<option value="MD"<? if($varDlstate=="MD") echo(" selected=\"selected\"");?>>Maryland</option>
<option value="MA"<? if($varDlstate=="MA") echo(" selected=\"selected\"");?>>Massachusetts</option>
<option value="MI"<? if($varDlstate=="MI") echo(" selected=\"selected\"");?>>Michigan</option>
<option value="MN"<? if($varDlstate=="MN") echo(" selected=\"selected\"");?>>Minnesota</option>
<option value="MS"<? if($varDlstate=="MS") echo(" selected=\"selected\"");?>>Mississippi</option>
<option value="MO"<? if($varDlstate=="MO") echo(" selected=\"selected\"");?>>Missouri</option>
<option value="MT"<? if($varDlstate=="MT") echo(" selected=\"selected\"");?>>Montana</option>
<option value="NE"<? if($varDlstate=="NE") echo(" selected=\"selected\"");?>>Nebraska</option>
<option value="NV"<? if($varDlstate=="NV") echo(" selected=\"selected\"");?>>Nevada</option>
<option value="NH"<? if($varDlstate=="NH") echo(" selected=\"selected\"");?>>New Hampshire</option>
<option value="NJ"<? if($varDlstate=="NJ") echo(" selected=\"selected\"");?>>New Jersey</option>
<option value="NM"<? if($varDlstate=="NM") echo(" selected=\"selected\"");?>>New Mexico</option>
<option value="NY"<? if($varDlstate=="NY") echo(" selected=\"selected\"");?>>New York</option>
<option value="NC"<? if($varDlstate=="NC") echo(" selected=\"selected\"");?>>North Carolina</option>
<option value="ND"<? if($varDlstate=="ND") echo(" selected=\"selected\"");?>>North Dakota</option>
<option value="OH"<? if($varDlstate=="OH") echo(" selected=\"selected\"");?>>Ohio</option>
<option value="OK"<? if($varDlstate=="OK") echo(" selected=\"selected\"");?>>Oklahoma</option>
<option value="OR"<? if($varDlstate=="OR") echo(" selected=\"selected\"");?>>Oregon</option>
<option value="PA"<? if($varDlstate=="PA") echo(" selected=\"selected\"");?>>Pennsylvania</option>
<option value="RI"<? if($varDlstate=="RI") echo(" selected=\"selected\"");?>>Rhode Island</option>
<option value="SC"<? if($varDlstate=="SC") echo(" selected=\"selected\"");?>>South Carolina</option>
<option value="SD"<? if($varDlstate=="SD") echo(" selected=\"selected\"");?>>South Dakota</option>
<option value="TN"<? if($varDlstate=="TN") echo(" selected=\"selected\"");?>>Tennessee</option>
<option value="TX"<? if($varDlstate=="TX") echo(" selected=\"selected\"");?>>Texas</option>
<option value="UT"<? if($varDlstate=="UT") echo(" selected=\"selected\"");?>>Utah</option>
<option value="VT"<? if($varDlstate=="VT") echo(" selected=\"selected\"");?>>Vermont</option>
<option value="VA"<? if($varDlstate=="VA") echo(" selected=\"selected\"");?>>Virginia</option>
<option value="WA"<? if($varDlstate=="WA") echo(" selected=\"selected\"");?>>Washington</option>
<option value="WV"<? if($varDlstate=="WV") echo(" selected=\"selected\"");?>>West Virginia</option>
<option value="WI"<? if($varDlstate=="WI") echo(" selected=\"selected\"");?>>Wisconsin</option>
<option value="WY"<? if($varDlstate=="WY") echo(" selected=\"selected\"");?>>Wyoming</option>
</select>
          </p>
 
    
           <p>
<label for='formGender'>Gender?</label><br/>
<select name="formGender">
<option value="">Select...</option>
<option value="M"<? if($varGender=="M") echo(" selected=\"selected\"");?>>Male</option>
<option value="F"<? if($varGender=="F") echo(" selected=\"selected\"");?>>Female</option>
</select>
 </p>
            
<input type="submit" name="formSubmit" value="Submit" />
</form>
 
</p>
 
</body>
</html>
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.