Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7618539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:25:48+00:00 2026-05-31T03:25:48+00:00

I have a contact form that has a dropdown to choose which department the

  • 0

I have a contact form that has a dropdown to choose which department the enquiry should go to…

<form action="contact-send.php" id="callback" method="post">
    <ul>
    <li class="left">
    <label for="name"><span class="required">*</span> Your Name</label>
    <br>
    <input type="text" id="name" name="name" value="<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['name'] : '' ?>" placeholder="John Doe" required autofocus /></li>
    <li class="right">
    <label for="email"><span class="required">*</span> Email Address</label>
    <br>
    <input type="email" id="email" name="email" value="<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['email'] : '' ?>" placeholder="johndoe@example.com" required /></li>
    <div class="clear"></div>
    <li class="left">
    <label for="enquiry"><span class="required">*</span> Enquiry</label><br>
    <select id="enquiry" name="enquiry">
        <option value="Admin / Accounts enquiry" <?php echo ($sr && !$cf['form_ok'] && $cf['posted_form_data']['enquiry'] == 'Admin / Accounts enquiry') ? "selected='selected'" : '' ?>>Admin / Accounts enquiry</option>
        <option value="Plant Hire / Haulage / Recycling / Contract Earthworks" <?php echo ($sr && !$cf['form_ok'] && $cf['posted_form_data']['enquiry'] == 'Plant Hire / Haulage / Recycling / Contract Earthworks') ? "selected='selected'" : '' ?>>Plant Hire / Haulage / Recycling / Contract Earthworks</option>
        <option value="Waste Management / Skip Hire" <?php echo ($sr && !$cf['form_ok'] && $cf['posted_form_data']['enquiry'] == 'Waste Management / Skip Hire') ? "selected='selected'" : '' ?>>Waste Management / Skip Hire</option>
    </select></li>
    <li>
    <label for="message"><span class="required">*</span> Message</label><br />
    <textarea id="message" name="message" placeholder="Your message must be greater than 20 charcters" required data-minlength="20"><?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['message'] : '' ?></textarea>
    </li>
    </ul>
    <div class="clear"></div>
    <p class="form-button right"><input class="submit" id="callback-submit" name="submit" value="Send" type="submit"></p>
</form>

I’m trying to figure out how to modify the following process script so that it sends the enquiry to a specified email address, depending on which department is selected…

<?php
function clean_input($input){
return strip_tags(trim($input));
}
if( isset($_POST) ){

    //form validation vars
    $formok = true;
    $errors = array();

    //sumbission data
    $ipaddress = $_SERVER['REMOTE_ADDR'];
    $date = date('d/m/Y');
    $time = date('H:i:s');

    //form data
    $name = clean_input($_POST['name']);
    $email = clean_input($_POST['email']);
    $enquiry = clean_input($_POST['enquiry']);
    $message = clean_input($_POST['message']);

    //validate form data

    //validate name is not empty
    if(empty($name)){
        $formok = false;
        $errors[] = "You have not entered a name";
    }

    //validate email address is not empty
    if(empty($email)){
        $formok = false;
        $errors[] = "You have not entered an email address";
    //validate email address is valid
    }elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
        $formok = false;
        $errors[] = "You have not entered a valid email address";
    }

    //validate message is not empty
    if(empty($message)){
        $formok = false;
        $errors[] = "You have not entered a message";
    }
    //validate message is greater than 20 charcters
    elseif(strlen($message) < 20){
        $formok = false;
        $errors[] = "Your message must be greater than 20 characters";
    }

    //send email if all is ok
    if($formok){
        ini_set("sendmail_from","EMAIL_ADDRESS"); 
        $headers = "From: EMAIL_ADDRESS" . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

        $emailbody = "<p>You have received a new contact us enquiry.</p>
                      <p><strong>Name: </strong> {$name} </p>
                      <p><strong>Email: </strong> {$email} </p>
                      <p><strong>Enquiry: </strong> {$enquiry} </p>
                      <p><strong>Message: </strong> {$message} </p>
                      <p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";

        mail("EMAIL_ADDRESS","Contact us enquiry",$emailbody,$headers);

    }

    //what we need to return back to our form
    $returndata = array(
        'posted_form_data' => array(
            'name' => $name,
            'email' => $email,
            'enquiry' => $enquiry,
            'message' => $message
        ),
        'form_ok' => $formok,
        'errors' => $errors
    );


    //if this is not an ajax request
    if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest'){
        //set session variables
        session_start();
        $_SESSION['cf_returndata'] = $returndata;

        //redirect back to form
        header('location: ' . $_SERVER['HTTP_REFERER']);
    }
}

I would be grateful if anyone could provide some pointers.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:25:49+00:00Added an answer on May 31, 2026 at 3:25 am

    Using the name of the form element you used to represent the department, just use a switch case to change the delivery address?

    It may be worth noting that simpler values, such as admin_enquiry rather than Admin / account enquiry may be easier to match against.

    switch ($select_department)
    {
        case "admin_enquiry":
            // Set to email as appropriate
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a PHP contact form that submits data, and an email...: <?php $dbh=mysql_connect
I have a contact page (contact.php) that sends a form (formsend.php) when people fill
I have a contact form that has a drop-down for referral source. If Magazine
I have a simple contact form on a website that has 2 text fields,
I have a page that has a Contact Form slide down when a link
I have created a contact form that has a disabled submit button until all
I have an insurance entry form that has contact information for two people. I
I have a contact form that can be hidden using .slideToggle() but I want
I have a contact us form that uses Ajax (i.e. relies on asynchronous requests).
I have an Ajax contact form that links to a jquery file but for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.