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 protected]"; $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 protected] and 2 goes to [email protected] 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. Link to comment https://forums.phpfreaks.com/topic/96423-contact-form-help/ Share on other sites More sharing options...
Orio Posted March 16, 2008 Share Posted March 16, 2008 Replace this line: $to = "[email protected]"; With: if($_POST['radio'] == 1) $to = "[email protected]"; else $to = "[email protected]"; Orio. Link to comment https://forums.phpfreaks.com/topic/96423-contact-form-help/#findComment-493518 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 [email protected] 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! Link to comment https://forums.phpfreaks.com/topic/96423-contact-form-help/#findComment-493557 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']; Link to comment https://forums.phpfreaks.com/topic/96423-contact-form-help/#findComment-493569 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.