GizmoPig Posted May 19, 2009 Share Posted May 19, 2009 Hi Sorry if I've miseed this one in the forums - have been searching for some time and nothing really matches the problem I'm having. I want to create a form that emails query to a different email address depending on what radio button is selected. I'm finding that my submit button isn't working. It's the first time that I've tried to do this particular form and have only been building php for a week or so, so please go easy on me (I do have proper training booked) This is the first time my submit hasn't worked so I'm wondering if the code that controls the email array means that I have to change the submit code? Just a guess. I've got the following html code: <form method="POST" action="housekeeping_mailer.php"> <input name="Name" type="text" id="Name" size="20"\><br /><br /> <b>Email Address:</b><br /> <input name="Email" type="text" id="Email" size="20"\> <p> <b>Mobile Number:</b><br /> <input name="Mobile" type="text" id="Mobile" size="20"\> <p> <b>Dealer(FCS) Code:</b><br /> <input name="FCS" type="text" id="FCS" size="20"\> <p> <b>Vehicle Registration:</b><br /> <input name="Reg" type="text" id="Reg" size="20"\> <p> <input type="radio" name="Query" value="Logistics" checked\> <b>Logistics Query </b></p> <input type="radio" name="Query" value="HPI"\> <b>HPI Query </b></p> <p> <input type="radio" name="Query" value="V5"\> <b>V5 Query </b></p> <p align="left"> <textarea name="Textarea" cols="50" rows="5">Type your query here...</textarea> <br /><br /><input type="submit" value="Submit" name="submit"></form> and the following php code: <?php if(isset($_POST['submit'])) { $name = $_POST["Name"]; $email = $_POST["Email"]; $mobile = $_POST["Mobile"]; $fcs = $_POST["FCS"]; $reg = $_POST["Reg"]; $subject = $_POST["Query"]; $logistics = $_POST["Logistics"]; //logistics $HPI = $_POST["HPI"]; //hpi $V5 = $_POST["V5"]; //v5 $message = $_POST["Textarea"]; $subject = "Housekeeping - $subject Query"; $emailgroup = $_POST["Query"]; $emailmessage = "Contacts Name: $name\nEmail Address: $email\nQuery Type: $subject\nQuery is: $message"; $email1 = "[email protected]"; $email2 = "[email protected]"; $email3 = "[email protected]"; if ($emailgroup == "logistics") {$messagesent = mail($email1, $subject, $emailmessage,"From: $email\r\n" . "Reply-To: $email"); include "./querysent.shtml";} elseif ($emailgroup == "HPI") {$messagesent = mail($email2, $subject, $emailmessage,"From: $email\r\n" . "Reply-To: $email"); include "./querysent.shtml";} elseif ($emailgroup == "V5") {$messagesent = mail($email3, $subject, $emailmessage,"From: $email\r\n" . "Reply-To: $email"); include "./querysent.shtml";} else include "./queryfailed.shtml"; ?> Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/158764-php-form-email-to-correct-person-based-on-radio-buttons/ Share on other sites More sharing options...
Hybride Posted May 19, 2009 Share Posted May 19, 2009 Not sure about the rest, but off the bat, you're missing a end parenthesis all the way at the bottom of the code. else include "./queryfailed.shtml"; } Quote Link to comment https://forums.phpfreaks.com/topic/158764-php-form-email-to-correct-person-based-on-radio-buttons/#findComment-837376 Share on other sites More sharing options...
GizmoPig Posted May 19, 2009 Author Share Posted May 19, 2009 That's got me a bit further - it sends to the php page now but still nothing in the inbox. Thanks for that one - at least I've got some change now so can work on why there's no email yet. Quote Link to comment https://forums.phpfreaks.com/topic/158764-php-form-email-to-correct-person-based-on-radio-buttons/#findComment-837391 Share on other sites More sharing options...
GizmoPig Posted May 20, 2009 Author Share Posted May 20, 2009 Ok, I'm now at a point where my queryfailed.shtml page is coming up when I submit the form. This appears to show it's working but could anyone help with getting the email to actually send. I haven't changed the code except for adding the missing } at the bottom of the code. Quote Link to comment https://forums.phpfreaks.com/topic/158764-php-form-email-to-correct-person-based-on-radio-buttons/#findComment-837946 Share on other sites More sharing options...
void Posted May 20, 2009 Share Posted May 20, 2009 <input type="radio" name="Query" value="Logistics" checked\> if ($emailgroup == "logistics") logistics != Logistics Quote Link to comment https://forums.phpfreaks.com/topic/158764-php-form-email-to-correct-person-based-on-radio-buttons/#findComment-837956 Share on other sites More sharing options...
Hybride Posted May 21, 2009 Share Posted May 21, 2009 Ok, I got flustered with this code and decided to redo it a bit to see how it worked. It had to do with your Query/radio buttons, so I fixed that and cleaned it up a little. Here's what I got: <form method="POST" action="housekeeping_mailer.php"> <input name="Name" type="text" id="Name" size="20"\><br /><br /> <b>Email Address:</b><br /> <input name="Email" type="text" id="Email" size="20"\> <p> <b>Mobile Number:</b><br /> <input name="Mobile" type="text" id="Mobile" size="20"\> <p> <b>Dealer(FCS) Code:</b><br /> <input name="FCS" type="text" id="FCS" size="20"\> <p> <b>Vehicle Registration:</b><br /> <input name="Reg" type="text" id="Reg" size="20"\> <p> <input type="radio" name="query" value="Logistics"\> <b>Logistics Query </b></p> <input type="radio" name="query" value="HPI"\> <b>HPI Query </b></p> <p> <input type="radio" name="query" value="V5"\> <b>V5 Query </b></p> <p align="left"> <textarea name="Textarea" cols="50" rows="5" >Type your query here...</textarea> <br /><br /><input type="submit" value="Submit" name="submit"><input type="hidden" value="submit" name="submitted"></form> <? $group = $_POST['query']; $name = $_POST["Name"]; $email = $_POST["Email"]; $mobile = $_POST["Mobile"]; $fcs = $_POST["FCS"]; $reg = $_POST["Reg"]; $subject = $_POST["Query"]; $Logistics = $_POST["Logistics"]; //logistics $HPI = $_POST["HPI"]; //hpi $V5 = $_POST["V5"]; //v5 $message = $_POST["Textarea"]; if(isset($_POST['submit'])) { $subject = "Housekeeping - $subject Query"; $emailgroup = $_POST["Query"]; $emailmessage = "Contacts Name: $name\nEmail Address: $email\nQuery Type: $subject\nQuery is: $message"; $email1 = "[email protected]"; $email2 = "[email protected]"; $email3 = "[email protected]"; switch($group) { case "Logistics": $messagesent = mail($email1, $subject, $emailmessage,"From: $email\r\n" . "Reply-To:$email"); include "./querysent.shtml"; break; case "HPI": $messagesent = mail($email2, $subject, $emailmessage,"From: $email\r\n" . "Reply-To: $email"); include "./querysent.shtml"; break; case "V5": $messagesent = mail($email3, $subject, $emailmessage,"From: $email\r\n" . "Reply-To: $email"); include "./querysent.shtml"; break; default: include "./queryfailed.shtml"; break; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/158764-php-form-email-to-correct-person-based-on-radio-buttons/#findComment-839115 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.