html - PHP E-mail Form: Different E-mails For Dropdown Menu -
html - PHP E-mail Form: Different E-mails For Dropdown Menu -
i've set php e-mail form , works fine. however, i'm not sure how create different subject selections send different e-mail addresses. please help me? give thanks you.
html:
<label><strong>subject:</strong></label> <select name="subject" size="1"> <option value="general feedback">general feedback</option> <option value="book information">book information</option> <option value="business inquiries">business inquiries</option> <option value="website related">website related</option> </select>
php:
<?php if(isset($_post['email'])) { // edit 2 lines below required $email_to = "the official website of ricky tsang <ricky@rickytsang.ca>"; $email_subject = $_request['subject']; function died($error) { // error code can go here echo "we sorry, there error(s) found form submitted. "; echo "these errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "please go , prepare these errors.<br /><br />"; die(); } // validation expected info exists if(!isset($_post['full_name']) || !isset($_post['email']) || !isset($_post['subject']) || !isset($_post['message'])) { died('we sorry, there appears problem form submitted.'); } $full_name = $_post['full_name']; $email_from = $_post['email']; $subject = $_post['subject']; $message= $_post['message']; $error_message = ""; $email_exp = '/^[a-za-z0-9._%-]+@[a-za-z0-9.-]+\.[a-za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'the e-mail entered not appear valid.<br />'; } $string_exp = "/^[a-za-z .'-]+$/"; if(!preg_match($string_exp,$full_name)) { $error_message .= 'the name entered not appear valid.<br />'; } if(strlen($message) < 2) { $error_message .= 'the message entered doee not appear valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); homecoming str_replace($bad,"",$string); } $email_message .= "full name: ".clean_string($full_name)."\n"; $email_message .= "e-mail: ".clean_string($email_from)."\n"; $email_message .= "subject: ".clean_string($subject)."\n"; $email_message .= "message: ".clean_string($message)."\n"; $email_from = $full_name.'<'.$email_from.'>'; // create email headers $headers = 'from: '.$email_from."\r\n". 'reply-to: '.$email_from."\r\n" . 'x-mailer: php/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include own success html here --> give thanks contacting official website of ricky tsang. in touch soon. <?php } ?>
may suggest this:
html snippet
you build select
using options in array below if wanted.
<label> <strong>subject:</strong> </label> <select name="subject" size="1"> <option value="1">general feedback</option> <option value="2">book information</option> <option value="3">business inquiries</option> <option value="4">website related</option> </select>
php snippet
<?php $subjects = array( 1 => array( 'to' => 'user@example.org', 'subject' => 'general feedback' ), 2 => array( 'to' => 'user@example.net', 'subject' => 'book information' ), 3 => array( 'to' => 'user@example.com', 'subject' => 'business inquiries' ), 4 => array( 'to' => 'anotheruser@example.org', 'subject' => 'website related' ) ); $email_to = ! empty($subjects[$_request['subject']]['to']) ? $subjects[$_request['subject']]['to'] : 'default@example.com'; $email_subject = ! empty($subjects[$_request['subject']]['subject']) ? $subjects[$_request['subject']]['subject'] : 'unknown subject';
php html css
Comments
Post a Comment