here0ugh Posted June 4, 2009 Share Posted June 4, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/160984-need-help-with-this-coding-bad/ Share on other sites More sharing options...
9three Posted June 4, 2009 Share Posted June 4, 2009 Your'e handling your arrays wrong. $array = array(); $array['FName'] = 'My First Name'; $array['LName'] = 'My Last Name'; //variable id will show FName. variable value will show whatever is in the quotes foreach ($array as $id => $value) { echo $value; } Quote Link to comment https://forums.phpfreaks.com/topic/160984-need-help-with-this-coding-bad/#findComment-849600 Share on other sites More sharing options...
here0ugh Posted June 4, 2009 Author Share Posted June 4, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/160984-need-help-with-this-coding-bad/#findComment-849604 Share on other sites More sharing options...
BobcatM Posted June 4, 2009 Share Posted June 4, 2009 {"Requested By"} needs to be ['Requested By'] Make them all like that. Quote Link to comment https://forums.phpfreaks.com/topic/160984-need-help-with-this-coding-bad/#findComment-849606 Share on other sites More sharing options...
here0ugh Posted June 4, 2009 Author Share Posted June 4, 2009 Ah, ok. Thanks a bunch for the tips guys! You're really helping me out. Im going to try now, i'll get back to you to see if it works... Quote Link to comment https://forums.phpfreaks.com/topic/160984-need-help-with-this-coding-bad/#findComment-849609 Share on other sites More sharing options...
here0ugh Posted June 4, 2009 Author Share Posted June 4, 2009 Yeah, changing the brackets didn't do anything, still having the same problem. So, im guessing it's the header problem someone 9three addressed, Did i get it right with how to replace the coding? Quote Link to comment https://forums.phpfreaks.com/topic/160984-need-help-with-this-coding-bad/#findComment-849612 Share on other sites More sharing options...
here0ugh Posted June 4, 2009 Author Share Posted June 4, 2009 None of the ways im trying to replace code with what was shown worked, ahhhh what am i doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/160984-need-help-with-this-coding-bad/#findComment-849624 Share on other sites More sharing options...
RClapham Posted June 4, 2009 Share Posted June 4, 2009 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"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/160984-need-help-with-this-coding-bad/#findComment-849629 Share on other sites More sharing options...
here0ugh Posted June 4, 2009 Author Share Posted June 4, 2009 YES! That worked! Thank you so much! I knew i was close! Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/160984-need-help-with-this-coding-bad/#findComment-849645 Share on other sites More sharing options...
RClapham Posted June 5, 2009 Share Posted June 5, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/160984-need-help-with-this-coding-bad/#findComment-849858 Share on other sites More sharing options...
here0ugh Posted June 5, 2009 Author Share Posted June 5, 2009 not a problem, thanks for the tip Quote Link to comment https://forums.phpfreaks.com/topic/160984-need-help-with-this-coding-bad/#findComment-850087 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.