srcfresno Posted August 24, 2011 Share Posted August 24, 2011 Below is my php file from my website srcfresno.com/inquiry2.htm When I go to the website and enter information in the form fields, it submits to my email fine but the email I receive has no information filled in. Please help. Not sure why !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Statistics & Research Consulting</title> </head> <?php $to = 'inquiry@srcfresno.com'; $subject = 'Contact Inquiry form'; $firstname = $_REQUEST['First Name'] ; $lastname = $_REQUEST['Last Name'] ; $from = $_REQUEST['Email'] ; $phone = $_REQUEST['Phone'] ; $company = $_REQUEST['Company Website (if applicable)'] ; $messege = $_REQUEST['Please describe your interest in Statistics & Research Consulting'] ; $fields = array( 'firstname' => 'First Name', 'lastname' => 'Last Name', 'from' => 'Email', 'phone' => 'Phone', 'company' => 'Company Website (if applicable)', 'message' => 'Please describe your interest in Statistics & Research Consulting' ); $body = "We have received the following information from $_SESSION[username]:\n\n"; foreach($_REQUEST as $a => $b){ if(array_key_exists($a, $fields) && !empty($b)){ $part1 .= sprintf("%20s: %s\n", $fields[$a], $b); } $send = mail($to, $subject, $body); if($send) {print "Thank you for contacting us. We have received your information and a SRC Consultant will respond shortly."; } else {print "We encountered an error sending your mail, please notify webmaster@srcfresno.com"; } ?> <body> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/245542-php-fields-array-help/ Share on other sites More sharing options...
jcbones Posted August 24, 2011 Share Posted August 24, 2011 Please post your form, inside the bbcode [ code ] [ /code ] tags! In the meantime, try changing. $part1 .= sprintf("%20s: %s\n", $fields[$a], $b); To: $body .= sprintf("%s: %s\n", $fields[$a], $b); Quote Link to comment https://forums.phpfreaks.com/topic/245542-php-fields-array-help/#findComment-1261139 Share on other sites More sharing options...
srcfresno Posted August 24, 2011 Author Share Posted August 24, 2011 This is the correct php code <?php $to = 'inquiry@srcfresno.com'; $subject = 'Contact Inquiry form'; $firstname = $_REQUEST['First Name'] ; $lastname = $_REQUEST['Last Name'] ; $from = $_REQUEST['Email'] ; $phone = $_REQUEST['Phone'] ; $company = $_REQUEST['Company Website (if applicable)'] ; $messege = $_REQUEST['Please describe your interest in Statistics & Research Consulting'] ; $fields = array( 'firstname' => 'First Name', 'lastname' => 'Last Name', 'from' => 'Email', 'phone' => 'Phone', 'company' => 'Company Website (if applicable)', 'message' => 'Please describe your interest in Statistics & Research Consulting' ); $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $send = mail($to, $subject, $body); if($send) {print "Thank you for contacting us. We have received your information and a SRC Consultant will respond shortly."; } else {print "We encountered an error sending your mail, please notify webmaster@srcfresno.com"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/245542-php-fields-array-help/#findComment-1261149 Share on other sites More sharing options...
srcfresno Posted August 24, 2011 Author Share Posted August 24, 2011 If anyone has an easier way to write the code i'm open to it. I just want the text in the fields listed emailed. Quote Link to comment https://forums.phpfreaks.com/topic/245542-php-fields-array-help/#findComment-1261162 Share on other sites More sharing options...
jcbones Posted August 24, 2011 Share Posted August 24, 2011 We really need to see the form! I'm not sure you are asking for the correct inputs. Quote Link to comment https://forums.phpfreaks.com/topic/245542-php-fields-array-help/#findComment-1261167 Share on other sites More sharing options...
srcfresno Posted August 24, 2011 Author Share Posted August 24, 2011 <body><form action="contact.php" method="post" enctype="multipart/form-data" name="input" target=_blank> <h2><span class="style14">Contact Inquiry Form </span></h2> <p> </p> <p> <span class="style24 style2">Customer Name</span> <br> <input name="textfield" type="text" size="50"> First Name<br> <br> <input name="textfield" type="text" size="50"> Last Name</br> </p> <p> <span class="style24 style2">Email</span><br> <input name="textfield" type="text" size="50"> </br> </p> <p> <span class="style24 style2">Phone</span> <br> <input name="textfield" type="text" size="50"> </br> </p> <p> <span class="style24 style2">Company Website (if applicable)</span> <br> <input name="textfield" type="text" size="50"> </br> </p> <p> <span class="style24 style2">Please describe your interest in Statistics & Research Consulting</span> <br> <textarea name="textarea" cols="50" rows="10"></textarea> </br></p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/245542-php-fields-array-help/#findComment-1261171 Share on other sites More sharing options...
jcbones Posted August 24, 2011 Share Posted August 24, 2011 Try Form <body><form action="contact.php" method="post" name="input" target=_blank> <h2><span class="style14">Contact Inquiry Form </span></h2> <p> </p> <p> <span class="style24 style2">Customer Name</span> <br> <input name="firstname" type="text" size="50"> First Name<br> <br> <input name="lastname" type="text" size="50"> Last Name</br> </p> <p> <span class="style24 style2">Email</span><br> <input name="email" type="text" size="50"> </br> </p> <p> <span class="style24 style2">Phone</span> <br> <input name="phone" type="text" size="50"> </br> </p> <p> <span class="style24 style2">Company Website (if applicable)</span> <br> <input name="company" type="text" size="50"> </br> </p> <p> <span class="style24 style2">Please describe your interest in Statistics & Research Consulting</span> <br> <textarea name="message" cols="50" rows="10"></textarea> </br></p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> contact <?php $to = 'inquiry@srcfresno.com'; $subject = 'Contact Inquiry form'; if (get_magic_quotes_gpc()) { $_POST = array_map('stripslashes',$_POST); } $fields = array( 'firstname' => 'First Name', 'lastname' => 'Last Name', 'email' => 'Email', 'phone' => 'Phone', 'company' => 'Company Website (if applicable)', 'message' => 'Please describe your interest in Statistics & Research Consulting' ); $body = "We have received the following information:\n\n"; foreach($fields as $a => $b) { if(array_key_exists($a,$_POST)) { $body .= sprintf("%s: %s\n",$b,$_POST[$a]); } } $send = mail($to, $subject, $body); if($send) {print "Thank you for contacting us. We have received your information and a SRC Consultant will respond shortly."; } else {print "We encountered an error sending your mail, please notify webmaster@srcfresno.com"; } ?> Let us know how it goes. Quote Link to comment https://forums.phpfreaks.com/topic/245542-php-fields-array-help/#findComment-1261186 Share on other sites More sharing options...
srcfresno Posted August 24, 2011 Author Share Posted August 24, 2011 Worked! Thank you... I was going crazy with this. I don't get the if (get_magic_quotes_gpc( and array_map('stripslashes' but whatever, it worked. Quote Link to comment https://forums.phpfreaks.com/topic/245542-php-fields-array-help/#findComment-1261203 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.