dare87 Posted December 9, 2007 Share Posted December 9, 2007 I have an email form and it works great. I would like to make some modifications and I am having trouble. Instead of just sending the email to the person that I set I want them to be able to choose them from a list. Thanks <?php if (!isset($_POST['submit'])) { // Show the form. echo '<form action="contact.php" method="post"> <fieldset><legend>Contact Us</legend> <table align="center" width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left"><b>Name:</b></td> <td align="left"><input type="text" class="required" name="name" size="20" value="'.$name.'" maxlength="40" /></td> </tr> <tr> <td align="left"><b>Email Address:</b></td> <td align="left"><input type="text" class="required" name="email" size="40" value="'.$email.'" maxlength="40" /></td> </tr> <tr> <td align="left"><b>Subject:</b></td> <td align="left"><input type="text" class="required" name="subject" size="40" value="'.$subject.'" maxlength="40" /></td> </tr> <tr> <td align="left"><b>Message:</b></td> <td align="left"><textarea class="required" name="body" rows="4" cols="40">'. $body.'</textarea></td> </tr> </table> </fieldset> <div align="left"> <input type="submit" class="button" name="submit" value="Send Message" /></div> <input type="hidden" class="button" name="submitted" value="TRUE" /> </form>'; echo 'All fields are required.'; } else { // Validate the name and combat Magic Quotes. if (!empty($_REQUEST['name'])) { $name = stripslashes($_REQUEST['name']); } // Validate the email. if (!empty($_REQUEST['email'])) { $email = $_REQUEST['email']; } // Validate Subject. if (!empty($_REQUEST['subject'])) { $subject = $_REQUEST['subject']; } // Validate Message and combat Magic Quotes. if (!empty($_REQUEST['body'])) { $body = stripslashes($_REQUEST['body']); } // If everything has a value, check the email syntax. if ($name && $email && $subject && $body) { // Validate the email syntax. list($username,$domain) = split("@",$email); if (eregi ('^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', $_POST['email'])) { echo "<p>Thank you, $name. We will reply to your message at $email. <br /></p>"; $headers = "From: {$_POST['name']}\r\n"; $headers .= "Reply-To: {$_POST['email']}\r\n"; mail ('[email protected]', $subject, $body, $headers); } else { echo '<p><font color="red"><strong>Please enter a valid e-mail address.</strong></font></p>'; echo '<form action="contact.php" method="post"> <fieldset><legend>Contact Us</legend> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left"><b>Name:</b></td> <td align="left"><input type="text" class="required" name="name" size="20" value="'.$name.'" maxlength="40" /></td> </tr> <tr> <td align="left"><b>Email Address:</b></td> <td align="left"><input type="text" class="required" name="email" size="40" value="'.$email.'" maxlength="40" /></td> </tr> <tr> <td align="left"><b>Subject:</b></td> <td align="left"><input type="text" class="required" name="subject" size="40" value="'.$subject.'" maxlength="40" /></td> </tr> <tr> <td align="left"><b>Message:</b></td> <td align="left"><textarea class="required" name="body" rows="4" cols="40">'. $body.'</textarea></td> </tr> </table> </fieldset> <div align="left"> <input type="submit" class="button" name="submit" value="Send Message" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form>'; echo 'All fields are required.'; } } else { echo '<p><font color="red"><strong>You forgot to enter one or more required fields.</strong></font></p>'; echo '<form action="contact.php" method="post"> <fieldset><legend>Contact Us</legend> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left"><b>Name:</b></td> <td align="left"><input type="text" class="required" name="name" size="20" value="'.$name.'" maxlength="40" /></td> </tr> <tr> <td align="left"><b>Email Address:</b></td> <td align="left"><input type="text" class="required" name="email" size="40" value="'.$email.'" maxlength="40" /></td> </tr> <tr> <td align="left"><b>Subject:</b></td> <td align="left"><input type="text" class="required" name="subject" size="40" value="'.$subject.'" maxlength="40" /></td> </tr> <tr> <td align="left"><b>Message:</b></td> <td align="left"><textarea class="required" name="body" rows="4" cols="40">'. $body.'</textarea></td> </tr> </table> </fieldset> <div align="left"> <input type="submit" class="button" name="submit" value="Send Message" /></div> <input type="hidden" class="button" name="submitted" value="TRUE" /> </form>'; echo 'All fields are required.'; } } // End of main isset() IF. ?> Link to comment https://forums.phpfreaks.com/topic/80865-solved-contact-form-help/ Share on other sites More sharing options...
dare87 Posted December 9, 2007 Author Share Posted December 9, 2007 Also, if anyone knows of an example that I could look at, that would be great too. Anything to help D Link to comment https://forums.phpfreaks.com/topic/80865-solved-contact-form-help/#findComment-410234 Share on other sites More sharing options...
graham23s Posted December 9, 2007 Share Posted December 9, 2007 Hi Mate, just make a drop down box with different emails: <?php <select name="emails"> <option value="email1">email1</option> <option value="email2">email2</option> </select> ## grab the email $emailtosendto = mysql_real_escape_string($_POST['emails']); ## then in the mail part do something like $to = $emailtosendto; ?> is that kinda what you were after? Graham Link to comment https://forums.phpfreaks.com/topic/80865-solved-contact-form-help/#findComment-410258 Share on other sites More sharing options...
dare87 Posted December 9, 2007 Author Share Posted December 9, 2007 Thanks that worked great. Now I just have to get it to pull the values from a table. D Link to comment https://forums.phpfreaks.com/topic/80865-solved-contact-form-help/#findComment-410559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.