Jump to content

Recommended Posts

Alright so, i'm trying to get this php to work, the forms are made out, and the php directory that it points tolooks legit enough, problem is when the user submits their information, there are missing fields:

 

Requested By

Insured Company Name

Certificate Holder

Phone Number

Zip Code

Job Description

Job Number

Additional Insured

Primary Wording

Certificate Holder Fax Number

Certificate Holder Requirements

 

If anyone can help me figure out why these fields aren't coming through on the forms when the email is sent, You will be saving my life!! THIS IS DRIVING ME NUTS!

 

Obviously, i changed the email addy and the URL to not give out the company url or the email.

 

Thanks in advance.

 

<?php 
$to = "myemail@email.com,"; 
$from = $_REQUEST['Email']; 
$name = $_REQUEST['Requested_By'];
$subject = "Request Certificate"; 

$fields = array(); 
$fields{"Requested By"} = "Requested_By"; 
$fields{"Insured Company Name"} = "Insured_Company_Name"; 
$fields{"Certificate Holder"} = "Certificate_Holder";
$fields{"Email"} = "Email"; 
$fields{"Address1"} = "Address1"; 
$fields{"Address2"} = "Address2"; 
$fields{"Phone"} = "Phone_Number"; 
$fields{"City"} = "City"; 
$fields{"State"} = "State"; 
$fields{"Zip Code"} = "Zip_Code"; 
$fields{"Attention"} = "Attention"; 
$fields{"Job Description"} = "Job_Description"; 
$fields{"Job Number"} = "Job_Number"; 
$fields{"Additional Insured"} = "Additional_Insured"; 
$fields{"Primary Wording"} = "Primary_wording"; 
$fields{"General Liability"} = "Coverage-General_Liability"; 
$fields{"Auto Liability"} = "Coverage-Auto_Liability"; 
$fields{"Workers' Compensation"} = "Coverage-Workers_Comp"; 
$fields{"Umbrella Policy"} = "Coverage-Umbrella_Policy";
$fields{"Evidence of Property"} = "Coverage-Evidence_of_Property"; 
$fields{"Certificate Holder Fax"} = "Certificate_Holder_Fax_Number"; 
$fields{"Notes (Certificate Holder's Requirements if Applicable)"} = "Certificate_Holder_Requirements"; 

$body = "We have received the following information:\r\n\r\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\r\n",$b,$_REQUEST[$a]); } 

if($name == '') {print "You have not entered a name, please go back and try again";} 
else { 
$send = mail($to, $subject, $body); 
if($send) 
{header( "Location: http://www.companyname.com/thanks.php" );} 
else 
{print "We encountered an error sending your mail, please notify .com"; } 
}
?>

 

And here's the form coding:

 

            <form method="POST" action="/sendmail.php" name="Request Insurance Certificate">             
              <input type=hidden name="success" value="http://www.companyname.com/thanks.php">
<table width="704" border="0" cellpadding="0" cellspacing="0" style="padding:0px; margin:0px;">
  <tr>
    <td width="171" height="32" class="textalign">Requested By:</td>
    <td width="146"><input class="txt" type="text" name="Requested_By" size="20" style="width:132px;"></td>
    <td width="169" class="textalign">Insured Company Name:</td>
    <td width="218"><input class="txt" type="text" name="Insured_Company_Name" size="20" style="width:132px;"></td>
  </tr>
  <tr>
    <td width="171" height="32" class="textalign">Certificate Holder:</td>
    <td width="146"><input class="txt" type="text" name="Certificate_Holder" size="20" style="width:132px;"></td>
     <td width="171" height="32" class="textalign">Email:</td>
     <td><input class="txt" type="text" name="Email" size="40" style="width:255px;"></td>
</tr>
   <tr>
  	<td height="32" colspan="4">
    	<table width="704" cellpadding="0" cellspacing="0" border="0">
        	<tr>
            	<td>Address1:</td>
                <td><input class="txt" type="text" name="Address1" size="40" style="width:255px;"></td>
                <td>Address2:</td>
                <td><input class="txt" type="text" name="Address2" size="40" style="width:255px;"></td>
            </tr>
        </table>
    </td>
  </tr>
  <tr>
  	<td height="32" colspan="4">
    	<table width="704" cellpadding="0" cellspacing="0" border="0">
        	<tr>
            	<td class="textalign">City:</td>
                <td><input class="txt" type="text" name="City" size="20" style="width:154px;"></td>
                <td class="textalign">State:</td>
                <td><input class="txt" type="text" name="State" size="2" style="width:154px;"></td>
                <td class="textalign">Zip Code:</td>
                <td><input class="txt" type="text" name="Zip_Code" size="10" style="width:153px;"></td>
            </tr>
        </table>
    </td>
  </tr>
  <tr>
  	<td height="32" colspan="4">
    	<table width="704" cellpadding="0" cellspacing="0" border="0">
        	<tr>
            	<td width="138" class="textalign">Phone:</td>
                <td width="126"><input class="txt" type="text" name="Phone_Number" size="20" style="width:115px;"></td>
                <td width="72" class="textalign">Attention:</td>
                <td width="117"><input class="txt" type="text" name="Attention" size="2" style="width:115px;"></td>
                <td width="113" class="textalign">Job Description:</td>
                <td width="138"><input class="txt" type="text" name="Job_Description" size="10" style="width:115px;"></td>
            </tr>
        </table>
    </td>
  </tr>
  <tr>
  	<td height="32" colspan="6">
    	<table width="704" cellpadding="0" cellspacing="0" border="0">
        	<tr>
            	<td width="138" class="textalign">Job Number:</td>
                <td width="126"><input class="txt" type="text" name="Job_Number" size="20" style="width:207px;"></td>
            </tr>
        </table>
    </td>
  </tr>
  <tr>
  	<td height="32" colspan="6"><span class="txtsize">*Does the Certificate Holder need to be added as an...</span></td>
  </tr>
  <tr>
  	<td height="32" colspan="6">
    	<table width="704" cellpadding="0" cellspacing="0" border="0">
        	<tr>
            	<td width="333" class="textalign">Additional Insured:</td>
                <td width="58">
   	<select name="Additional_Insured" size="1" class="txt">
                              <option value="Yes">Yes</option>
                              <option selected value="No">No</option>
                    </select>
                </td>
                <td width="141" class="textalign">Primary Wording:</td>
                <td width="172">
				<select name="Primary_Wording" size="1" class="txt">
                      <option selected value="No">No</option>
                      <option value="Yes">Yes</option>
                    </select>
                </td>
            </tr>
        </table>
    </td>
  </tr> 
  <tr>
  	<td height="32" colspan="6"><span class="txtsize">*Coverage's Needed</span></td>
  </tr>
  <tr>
  	<td height="32" colspan="6">
  	    	<table width="704" cellpadding="0" cellspacing="0" border="0">
        	<tr>
            	<td width="152" class="textalign">General Liability:</td>
                <td width="20"><input class="txt" type="checkbox" name="Coverage-General_Liability" value="Yes"></td>
                <td width="101" class="textalign">Auto Liability:</td>
                <td width="20"><input class="txt" type="checkbox" name="Coverage-Auto_Liability" value="Yes"></td>
                <td width="172" class="textalign">Workers' Compensation:</td>
                <td width="20"><input class="txt" type="checkbox" name="Coverage-Workers_Comp" value="Yes"></td>
                <td width="183" class="textalign">Umbrella Policy (Optional):</td>
                <td width="36"><input class="txt" type="checkbox" name="Coverage-Umbrella_Policy" value="Yes"></td>
            </tr>
        </table>
     </td>
  </tr>
  <tr>
  	<td height="32" colspan="6">
  	    	<table width="704" cellpadding="0" cellspacing="0" border="0">
        	<tr>
            	<td width="477" class="textalign">Evidence of Property (Building, Personal Property, Etc...):</td>
                <td width="227"><input class="txt" type="checkbox" name="Coverage-Evidence_of_Property" value="Yes"></td>
            </tr>
        </table>
     </td>
  </tr>
  <tr>
  	<td height="32" colspan="6">
  	    	<table width="704" cellpadding="0" cellspacing="0" border="0">
        	<tr>
            	<td width="477" class="textalign">Fax Number of the Certificate Holder:</td>
                <td width="227"><input class="txt" type="text" name="Certificate_Holder_Fax_Number" size="20"></td>
            </tr>
        </table>
     </td>
  </tr>
  <tr>
  	<td height="32" colspan="6"><span class="txtsize">*Note: Certificate Holder's Requirements if applicable.</span></td>
  </tr>
  <tr>
  	<td height="32" colspan="6" style="text-align:center;">
    	<textarea class="txt" name="Certificate_Holder_Requirements" cols="60" rows="5" style="width:416px; height:75px;"></textarea>
    </td>
  </tr>
  <tr>
  	<td height="32" colspan="6" style="text-align:center; padding-bottom:10px; padding-top:10px;">
    <span class="block">
    Please verify that all information entered is correct<br />before pressing the <b>"Submit"</b> Button. Thank you.
</span>
    </td>
  </tr>
  <tr>
  	<td height="32" colspan="6">
    	<table width="704" cellpadding="0" cellspacing="0" border="0">
        	<tr>
            	<td style="text-align:right;">
                <input name="B1" src="images/submit.png" type="image" style="width:91px; height:23px;" value="Submit" alt="Submit" />
                </td>
                <td>

<input name="B2" src="images/reset.png" type="image" style="width:91px; height:23px;" value="Reset" alt="Reset" /></td>
            </tr>
        </table>
    </td>
  </tr>
</table>
</form>

Link to comment
https://forums.phpfreaks.com/topic/160984-need-help-with-this-coding-bad/
Share on other sites

ahhhh ok, makes sense.

So, as far as placing this.

 

I replace the fields with, array instead?

And for the code after body,

; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\r\n",$b,$_REQUEST[$a]); }

I replace with

foreach ($array as $id => $value)
{
  echo $value;
}

 

Do i have it right?

Sorry if these questions are super obvious, i'm kind of new to php

Like this it should work, I haven't really changed much but I know that it should definitely work now:

 

$to = "myemail@email.com,"; 
$from = $_REQUEST['Email']; 
$name = $_REQUEST['Requested_By'];
$subject = "Request Certificate"; 

$fields = array(); 
$fields["Requested By"] = "Requested_By"; 
$fields["Insured Company Name"] = "Insured_Company_Name"; 
$fields["Certificate Holder"] = "Certificate_Holder";
$fields["Email"] = "Email"; 
$fields["Address1"] = "Address1"; 
$fields["Address2"] = "Address2"; 
$fields["Phone"] = "Phone_Number"; 
$fields["City"] = "City"; 
$fields["State"] = "State"; 
$fields["Zip Code"] = "Zip_Code"; 
$fields["Attention"] = "Attention"; 
$fields["Job Description"] = "Job_Description"; 
$fields["Job Number"] = "Job_Number"; 
$fields["Additional Insured"] = "Additional_Insured"; 
$fields["Primary Wording"] = "Primary_wording"; 
$fields["General Liability"] = "Coverage-General_Liability"; 
$fields["Auto Liability"] = "Coverage-Auto_Liability"; 
$fields["Workers' Compensation"] = "Coverage-Workers_Comp"; 
$fields["Umbrella Policy"] = "Coverage-Umbrella_Policy";
$fields["Evidence of Property"] = "Coverage-Evidence_of_Property"; 
$fields["Certificate Holder Fax"] = "Certificate_Holder_Fax_Number"; 
$fields["Notes (Certificate Holder's Requirements if Applicable)"] = "Certificate_Holder_Requirements"; 

$body = "We have received the following information:\r\n\r\n"; 

foreach($fields as $a => $b)
{ 
$body .= $a.": ".$_REQUEST[$b]."\n";
} 

if($name == '') {
print "You have not entered a name, please go back and try again";
} else { 
$send = mail($to, $subject, $body); 
if($send) {
header( "Location: http://www.companyname.com/thanks.php" );
} else {
print "We encountered an error sending your mail, please notify .com"; } 
}
?>

No problem, though in the future it's more grammatically correct to have it with the form field name as the array key, so: $fields["Zip_Code"] and have it be set to the name of the field, so $fields["Zip_Code"] = "Zip Code". It's all the same just reads nice imo that way.

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.