Braveheartt Posted March 16, 2008 Share Posted March 16, 2008 Hello! I'm brand new to PHP. I've made a simple contact form in HTML and PHP. It works perfectly. Now I'm having a little trouble with being able to choose who to send the completed form to! I have removed/changed all the links and email addresses on purpose. Here we go: This is my mail.php code: <?php if(isset($_POST['submit'])) { $to = "email@site.com"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message_cat = $_POST['message_cat']; $message = $_POST['message']; $subject = "$message_cat"; $option = $_POST['radio']; $body = "From:\n $name_field\n\n Email Address:\n $email_field\n\n Department: $option\n Message category:\n $message_cat\n\n Message:\n\n $message"; mail($to, $subject, $body); header('Location:*removed*); } else { echo "Oops! You shouldn't be here!"; } ?> Alright, that works perfectly with the accompanying HTML form. Now I made two radio buttons in my form: <input type="radio" value="1" name="radio"> Department 1 <br> <input type="radio" value="2" name="radio"> Department 2 Now the hard confusing bit, how do I get the &to variable to change to depending on which radio button is pressed? For example radio button 1 goes to email@site.com and 2 goes to email1@site.com Also where do I put the email addresses? I would rather the radio buttons be called form example "Department" and the email is assigned to it but hidden. How? Also an off-topic question, in the variable $body what do I use to make certain parts bold, underlined etc? How? Thanks! Brave. Quote Link to comment Share on other sites More sharing options...
Orio Posted March 16, 2008 Share Posted March 16, 2008 Replace this line: $to = "email@site.com"; With: if($_POST['radio'] == 1) $to = "department1@site.com"; else $to = "department2@site.com"; Orio. Quote Link to comment Share on other sites More sharing options...
Braveheartt Posted March 16, 2008 Author Share Posted March 16, 2008 Thank you for the quick and excellent reply Orio! It's working perfectly!! I have a couple more questions for anyone: 1. How can I make the output fields in the email bold, underlined etc. (For example the /n for new line) 2. At the moment the "from" email header has my website email address, how could I change that to read the "name" field in the email? This is how it looks: "From example@email.com Date&Time ##/## Subject". Hopefully you'll understand that one . 3. Is there anyway I could track the person who submitted the form's IP? And then show it in the email. Handy for banning spammers... Thanks again! Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 16, 2008 Share Posted March 16, 2008 1. you'll need to use mime formatted email to send HTML 2. mail($to, $subject, $body, $headers); check out the mail function's $headers. http://us3.php.net/function.mail 3. $ip = $_SERVER['REMOTE_ADDR']; Quote Link to comment 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.