php - Specific email conditional on Radio Button selected in Form -
thank info here, seem missing make send each particular email address.
basis code came thread: send php form different emails based on radio buttons
<form name="contact-form" method="post" action="contact.php"> <div class="form_details"> <input type="text" id="field_name" name="sender_name" class="text" value="name"> <input type="text" id="field_email" name="sender_email" class="text" value="email" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'email';}"> <input type="text" id="field_subject" name="sender_subject" class="text" value="subject" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'subject';}"> <textarea id="field_message" name="sender_message" value="message" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'message';}"></textarea> <div class="clearfix"> </div> <div class="sub-button"> <div style="float:left"> <input type="radio" name="department" value="archery"> archery <input type="radio" name="department" value="firearms"> firearms <input type="radio" name="department" value="general"> general inquiry </div> <div class="g-recaptcha" data-sitekey="6leydxctaaaaacbd4beoldgtu0liqztwojnvfsh-"></div> <input type="submit" name="send_message" value="submit"> </div> </div> </form> <?php // assigning data $_post array variables $name = $_post['sender_name']; $mail_from = $_post['sender_email']; $phone = $_post['sender_phone']; $sender_subject = $_post['sender_subject']; $message = $_post['sender_message']; $radio = isset($_post['archery']) ? $_post['firearms'] : $_post['general']; if (isset($_post['archery'])) { $department = 'info1@info.com'; } elseif (isset($_post['firearms'])) { $department = 'info2@info.com'; } elseif (isset($_post['general'])) { $department = 'info3@info.com'; } else { $department = 'info4@info.com'; } // construct email subject $subject = 'sc website message '; // construct email body $body_message .= 'from: ' . $name . "\r\n"; $body_message .= 'e-mail: ' . $mail_from . "\r\n"; $body_message .= 'subject: ' . $sender_subject . "\r\n"; $body_message .= 'message: ' . $message; // construct email headers $headers = 'from: ' . $mail_from . "\r\n"; $headers .= 'reply-to: ' . $mail_from . "\r\n"; $mail_sent = mail($mail_to, $subject, $body_message, $headers); if ($mail_sent == true){ ?> <script language="javascript" type="text/javascript"> alert('thank message, in contact shortly.'); window.location = 'contact.html'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('message not sent. please, notify site administrator info1@info.com'); window.location = 'contact.html'; </script> <?php } ?>
edit:
html
<form name="contact-form" method="post" action="contact.php"> <div class="form_details"> <input type="text" id="field_name" name="sender_name" class="text" placeholder="name"/> <input type="text" id="field_email" name="sender_email" class="text" value="email" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'email';}"/> <input type="text" id="field_subject" name="sender_subject" class="text" value="subject" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'subject';}"/> <textarea id="field_message" name="sender_message" placeholder="message" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'message';}"></textarea> <div class="clearfix"> </div> <div class="sub-button"> <div style="float:left"> <input type="radio" name="department" value="archery"/> archery <input type="radio" name="department" value="firearms"/> firearms <input type="radio" name="department" value="general"/> general inquiry </div> <div class="g-recaptcha" data-sitekey="6leydxctaaaaacbd4beoldgtu0liqztwojnvfsh-"></div> <input type="submit" name="send_message" value="submit"/> </div> </div> </form>
php
<?php if (isset($_post["send_message"])) { $name = $_post["sender_name"]; $mail_from = $_post["sender_email"]; //$phone = $_post["sender_phone"]; $sender_subject = $_post["sender_subject"]; $message = $_post["sender_message"]; $radio = $_post["department"]; if ($radio == "archery") { $department = "info1@info.com"; } elseif ($radio == "firearms") { $department = "info2@info.com"; } elseif ($radio == "general") { $department = "info3@info.com"; } else { $department = "info4@info.com"; } // construct email subject $subject = 'sc website message '; // construct email body $body_message = ""; $body_message .= 'from: ' . $name . "\r\n"; $body_message .= 'e-mail: ' . $mail_from . "\r\n"; $body_message .= 'subject: ' . $sender_subject . "\r\n"; $body_message .= 'message: ' . $message; // construct email headers $headers = 'from: ' . $mail_from . "\r\n"; $headers .= 'reply-to: ' . $mail_from . "\r\n"; // flow mail sent department $mail_to=$department; $mail_sent = mail($mail_to, $subject, $body_message, $headers); if ($mail_sent == true){ ?> <script language="javascript" type="text/javascript"> alert('thank message, in contact shortly.'); window.location = 't1.php'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('message not sent. please, notify site administrator info1@info.com'); window.location = 't1.php'; </script> <?php } } ?>
Comments
Post a Comment