cmbcorp Posted September 13, 2007 Share Posted September 13, 2007 Hi Guys/Gals, Having an issue with my php form.. Basically i want to make more than 2 fields mandatory.. Now everything worked ok with only the name and the email as mandatory, then i started playing around with it, here was the original code that "worked" <?php $to = $_REQUEST['sendto'] ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $headers = "From: $from"; $subject = "Counter Intelligence POS - Support Help Desk Form"; $fields = array(); $fields{"Name"} = "Name"; $fields{"Company"} = "Company"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $fields{"ciposver"} = "CIPosVersion"; $fields{"ciofficever"} = "CIOfficeVersion"; $fields{"cios"} = "CIOperatingSystems"; $fields{"Message"} = "CIDetailedIssue"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: noreply@counterintelligence.com.au"; $subject2 = "Thank you for contacting us"; $autoreply = "Thank you for for your query. A support representitive will be in contact with you shortly!."; if($from == '') {print "You have not entered an email, please go back and try again";} else { if($name == '') {print "You have not entered a name, please go back and try again";} else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) {header( "Location: http://www.counterintelligencepos.com.au/thankyou.html" );} else {print "We encountered an error sending your mail, please notify sales@counterintelligencepos.com.au"; } } } ?> then i played around with it, this is what i done: <?php $to = $_REQUEST['sendto'] ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $company = $_REQUEST['Company'] ; $phone = $_REQUEST['Phone'] ; $headers = "From: $from"; $subject = "Counter Intelligence POS - Support Help Desk Form"; $fields = array(); $fields{"Name"} = "Name"; $fields{"Company"} = "Company"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $fields{"ciposver"} = "CIPosVersion"; $fields{"ciofficever"} = "CIOfficeVersion"; $fields{"cios"} = "CIOperatingSystems"; $fields{"Message"} = "CIDetailedIssue"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: noreply@counterintelligence.com.au"; $subject2 = "Thank you for contacting us"; $autoreply = "Thank you for for your query. A support representitive will be in contact with you shortly!."; if($from == '') {print "You have not entered an email, please go back and try again";} else { if($name == '') {print "You have not entered a name, please go back and try again";} else { if($phone == '') {print "You have not entered a phone number, please go back and try again";} else { if($company == '') {print "You have not entered a company name, please go back and try again";} else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) {header( "Location: http://www.counterintelligencepos.com.au/thankyou.html" );} else {print "We encountered an error sending your mail, please notify sales@counterintelligencepos.com.au"; } } } ?> WHen i go to run my form, i get the following error message: Parse error: syntax error, unexpected $end in /home/counteri/public_html/contact_support.php on line 44 Am i doing something wrong? Not sure why i am getting these errors. Really appriciate your help guys.. Thanks. Jason. Quote Link to comment https://forums.phpfreaks.com/topic/69155-please-help-simple-php-contact-us-form-help/ Share on other sites More sharing options...
watthehell Posted September 13, 2007 Share Posted September 13, 2007 One extra brace at the last line hope this works <?php $to = $_REQUEST['sendto'] ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $company = $_REQUEST['Company'] ; $phone = $_REQUEST['Phone'] ; $headers = "From: $from"; $subject = "Counter Intelligence POS - Support Help Desk Form"; $fields = array(); $fields{"Name"} = "Name"; $fields{"Company"} = "Company"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $fields{"ciposver"} = "CIPosVersion"; $fields{"ciofficever"} = "CIOfficeVersion"; $fields{"cios"} = "CIOperatingSystems"; $fields{"Message"} = "CIDetailedIssue"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b) { $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: noreply@counterintelligence.com.au"; $subject2 = "Thank you for contacting us"; $autoreply = "Thank you for for your query. A support representitive will be in contact with you shortly!."; if($from == '') {print "You have not entered an email, please go back and try again";} else { if($name == '') {print "You have not entered a name, please go back and try again";} else { if($phone == '') {print "You have not entered a phone number, please go back and try again";} else { if($company == '') {print "You have not entered a company name, please go back and try again";} else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) { header( "Location: http://www.counterintelligencepos.com.au/thankyou.html" ); } else { print "We encountered an error sending your mail, please notify sales@counterintelligencepos.com.au"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69155-please-help-simple-php-contact-us-form-help/#findComment-347590 Share on other sites More sharing options...
cmbcorp Posted September 13, 2007 Author Share Posted September 13, 2007 HI i tried that code with the extra break, got another error message: Parse error: syntax error, unexpected $end in /home/counteri/public_html/contact_support.php on line 52 any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/69155-please-help-simple-php-contact-us-form-help/#findComment-347598 Share on other sites More sharing options...
watthehell Posted September 13, 2007 Share Posted September 13, 2007 If you get Undefined index, so please declare all variables null at the beginning <?php $to = $_REQUEST['sendto']; $from = $_REQUEST['Email']; $name = $_REQUEST['Name']; $company = $_REQUEST['Company']; $phone = $_REQUEST['Phone']; $headers = "From: $from"; $subject = "Counter Intelligence POS - Support Help Desk Form"; $fields = array(); $fields{"Name"} = "Name"; $fields{"Company"} = "Company"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $fields{"ciposver"} = "CIPosVersion"; $fields{"ciofficever"} = "CIOfficeVersion"; $fields{"cios"} = "CIOperatingSystems"; $fields{"Message"} = "CIDetailedIssue"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b) { $body.=sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: noreply@counterintelligence.com.au"; $subject2 = "Thank you for contacting us"; $autoreply = "Thank you for for your query. A support representitive will be in contact with you shortly!."; if($from=='') {print "You have not entered an email, please go back and try again";} if($name=='') {print "You have not entered a name, please go back and try again";} if($phone=='') {print "You have not entered a phone number, please go back and try again";} if($company=='') {print "You have not entered a company name, please go back and try again";} else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) { header("Location: http://www.counterintelligencepos.com.au/thankyou.html"); } else { echo "We encountered an error sending your mail, please notify sales@counterintelligencepos.com.au"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69155-please-help-simple-php-contact-us-form-help/#findComment-347651 Share on other sites More sharing options...
cmbcorp Posted September 13, 2007 Author Share Posted September 13, 2007 hi thanks so much for your help... i tried your code and when i didnt enter something in the phone number field, it sent the email, but before it sent the email it displayed the error message : You have not entered a phone number, please go back and try again Warning: Cannot modify header information - headers already sent by (output started at /home/counteri/public_html/contact_support.php:33) in /home/counteri/public_html/contact_support.php on line 42 Not sure why its sending the email without the phone number field filled in.. any ideas? THanks for your help.. cheers Quote Link to comment https://forums.phpfreaks.com/topic/69155-please-help-simple-php-contact-us-form-help/#findComment-347664 Share on other sites More sharing options...
watthehell Posted September 13, 2007 Share Posted September 13, 2007 Now try this <?php ob_start(); $to = $_REQUEST['sendto']; $from = $_REQUEST['Email']; $name = $_REQUEST['Name']; $company = $_REQUEST['Company']; $phone = $_REQUEST['Phone']; $headers = "From: $from"; $subject = "Counter Intelligence POS - Support Help Desk Form"; $fields = array(); $fields{"Name"} = "Name"; $fields{"Company"} = "Company"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $fields{"ciposver"} = "CIPosVersion"; $fields{"ciofficever"} = "CIOfficeVersion"; $fields{"cios"} = "CIOperatingSystems"; $fields{"Message"} = "CIDetailedIssue"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b) { $body.=sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: noreply@counterintelligence.com.au"; $subject2 = "Thank you for contacting us"; $autoreply = "Thank you for for your query. A support representitive will be in contact with you shortly!."; if($from=='') {print "You have not entered an email, please go back and try again";} if($name=='') {print "You have not entered a name, please go back and try again";} if($phone=='') {print "You have not entered a phone number, please go back and try again";} if($company=='') {print "You have not entered a company name, please go back and try again";} $isfreeofErrors=1; if ($isfreeofErrors==1) { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) { header("Location: http://www.counterintelligencepos.com.au/thankyou.html"); } else { echo "We encountered an error sending your mail, please notify sales@counterintelligencepos.com.au"; } } else { echo "Something is still wrong."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69155-please-help-simple-php-contact-us-form-help/#findComment-347675 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.