Kadage Posted January 13, 2011 Share Posted January 13, 2011 Hey everyone, i am currently working on a "contact us" script. I want the form to first allow the user which department they want to email. E.g. "Sales" and "Support" By changing this drop down box it will change which email the form is sent to. Im having trouble setting the PHP side of this script up to change the emails. Any help regarding this matter is much appreciated. HTML FORM: <form name="contactForm" method="post" action="forms/contactUs.php"> <table width="350" border="0"> <tr> <td width="150" class="bold">Department:</td> <td width="200" align="left"> <select name="department" class="dropDown"> <option value="sales">Sales</option> <option value="support">Support</option> </select> </td> </tr> <tr> <td class="bold">Full Name:</td> <td> <input name="name" type="text" class="contactTextBox" /> </td> </tr> <tr> <td class="bold">Company:</td> <td> <input name="company" type="text" class="contactTextBox" /> </td> </tr> <tr> <td class="bold">Email:</td> <td> <input name="email" type="text" class="contactTextBox" /> </td> </tr> <tr> <td class="bold">Comments:</td> <td> <textarea name="com" id="com" cols="5" rows="5" class="contactTextArea" /></textarea> </td> </tr> <tr> <td> </td> <td align="right"> <input type="submit" class="button" value="Submit" /> <input type="reset" class="button" value="Reset" /> </td> </tr> </table> </form> PHP <?php $department = $_POST['department']; $confirm = "sales"; if(isset($_POST['email'])) { if($department == $confirm) { $email_to = "[email protected]"; $email_subject = "Sales Question"; } else { $email_to = "[email protected]"; $email_subject = "Support Question"; } $fullName = $_POST['name']; $company = $_POST['company']; $email_from = $_POST['email']; $comments = $_POST['com']; $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 .= "Full Name: ".clean_string($fullName)."\n"; $email_message .= "Company: ".clean_string($company)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); header("location: ../contactSubmit.html"); ?> <? } ?> Link to comment https://forums.phpfreaks.com/topic/224291-php-multiple-if-statements/ Share on other sites More sharing options...
hyster Posted January 13, 2011 Share Posted January 13, 2011 at the end of the code change <? } ?> to <?php } ?> Link to comment https://forums.phpfreaks.com/topic/224291-php-multiple-if-statements/#findComment-1158830 Share on other sites More sharing options...
Kadage Posted January 13, 2011 Author Share Posted January 13, 2011 Still no luck It sends my to a white page and doesn't give me any errors... So i don't know whats wrong. Link to comment https://forums.phpfreaks.com/topic/224291-php-multiple-if-statements/#findComment-1158831 Share on other sites More sharing options...
hyster Posted January 13, 2011 Share Posted January 13, 2011 this is what i do to check functions and such. the post vars are passing over and ur if is working. sorry not more help. i dont have email on my test server. <?php $confirm = "sales"; $department = $_POST['department']; $fullName = $_POST['name']; $company = $_POST['company']; $email_from = $_POST['email']; $comments = $_POST['com']; echo "$fullName"; echo "<br>"; echo "$company"; echo "<br>"; echo "$email_from"; echo "<br>"; echo "$comments"; echo "<br>"; echo "$department"; echo "<br>"; if(isset($_POST['email'])) { if($department == $confirm) { $email_to = "[email protected]"; $email_subject = "Sales Question"; echo "match"; } else { $email_to = "[email protected]"; $email_subject = "Support Question"; echo "error"; } $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 .= "Full Name: ".clean_string($fullName)."\n"; $email_message .= "Company: ".clean_string($company)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); //header("location: ../contactSubmit.html");?> <?php echo "<br>"; echo "$headers"; echo "<br>"; echo "$email_message"; } ?> Link to comment https://forums.phpfreaks.com/topic/224291-php-multiple-if-statements/#findComment-1158849 Share on other sites More sharing options...
Kadage Posted January 13, 2011 Author Share Posted January 13, 2011 Yay! I got it working now, thanks a lot hyster!! Much appreciated Link to comment https://forums.phpfreaks.com/topic/224291-php-multiple-if-statements/#findComment-1158858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.