badproduce Posted October 16, 2007 Share Posted October 16, 2007 Okay,I need to update my email/contact form to have a choice of 1 of 3 people to contact,and I am a noob at this.Need some help. Heres my form: <h2>Contact The Webmaster</h2><br> <form method="POST" action="mailerwebmaster.php"> Your Name: <input type="text" name="name" size="19"><br> <br> Your Email Address: <input type="text" name="email" size="19"><br> <br> Question/Comments:<br> <textarea rows="9" name="message" cols="30"></textarea> <br> <br> <input type="submit" value="Submit" name="submit"> </form> Here's my php: <?php $to = "jondoe@gmail.com"; $subject = "Form Tutorial"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['message']; $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message"; echo ""; mail($to, $subject, $body); // Change to the URL you want to redirect to $URL="http://www.jondoe.org/thankyou.html"; header ("Location: $URL"); ?> Can I use checkboxes/dropdown and somehow make a choice setting in my PHP code? Quote Link to comment https://forums.phpfreaks.com/topic/73429-solved-email-formchoice-of-recipient-help/ Share on other sites More sharing options...
kellz Posted October 16, 2007 Share Posted October 16, 2007 <head> </head> <body> <form action="xx.php" method="post"> <select name="person"> <option value="person1@x.com">person 1</option> <option value="person2@x.com">person 2</option> <option value="person3@x.com">person 3</option> </select> <input type="submit" value="Send"> </p> </form> <?php if (isset($_POST['person'])) { $person = $_POST['person']; echo $person; } ?> </body> </html> and you should validate the input, because of stupid spammers! Quote Link to comment https://forums.phpfreaks.com/topic/73429-solved-email-formchoice-of-recipient-help/#findComment-370445 Share on other sites More sharing options...
badproduce Posted October 16, 2007 Author Share Posted October 16, 2007 Thank you,but this leads to another question. Exactly where/how would I place this in my html/php? Again,I apologize,new to the php thing,so my coding is shit. Quote Link to comment https://forums.phpfreaks.com/topic/73429-solved-email-formchoice-of-recipient-help/#findComment-370450 Share on other sites More sharing options...
kellz Posted October 16, 2007 Share Posted October 16, 2007 Just made this for you but it's probably not perfect: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Email Form</title> </head> <body> <form action="xx.php" method="post"> <p> <label>your name<br /> <input type="text" name="name" /> </label> <br /> <label>your email<br /> <input type="text" name="email" /> </label> <br /> <label>message <br /> <textarea name="comments"></textarea> </label> <br /> Send to: <br /> <select name="person"> <option value="person1@x.com">person 1</option> <option value="person2@x.com">person 2</option> <option value="person3@x.com">person 3</option> </select> <br /> <br /> <input type="submit" value="Send"> </p> </form> <?php if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['comments']) && isset($_POST['person'])) { //check if all form data has been filled in $name = $_POST['name'] ; $email = $_POST['email'] ; $comments = $_POST['comments'] ; $subject = 'Message From Visitor' ; $mailto = $_POST['person']; $http_referrer = getenv( "HTTP_REFERER" ); $uself = 1; $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ; $regexp = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/"; if (!preg_match($regexp, $email)) { echo 'incorrect email format!'; exit ; } $message = "This message was sent from:\n" . "$http_referrer\n" . "------------------------------------------------------------\n" . "Name of sender: $name\n" . "Email of sender: $email\n" . "------------------------- COMMENTS -------------------------\n\n" . $comments . "\n\n------------------------------------------------------------\n" ; mail($mailto, $subject, $message, "From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: kelzback.php 1.0" ); echo 'your message has been send to ' . $mailto; exit ; } ?> </body> </html> xx.php will be the name of this email form. so you should create a webpage called xx.php and paste this code in there. you can change the name but if you change the file to email.php don't forget to change the form action to "email.php" too!! if you have problems adding this to your webpage i'll do it for you if you have me the source code of the page.. im so nice!^^ actually i havnt tested it so good luck!^^ Quote Link to comment https://forums.phpfreaks.com/topic/73429-solved-email-formchoice-of-recipient-help/#findComment-370466 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.