trying to route emails in a contact form

I have created a contact form for a client. The contact form works fine, but I am struggling with the php code to execute it. I would like it to work where if the user selects “landscaping” from the drop down menu then an email is sent to “email a.” If the user selects “sitework” then an email is sent to “email b” and if they select “employment” the email is sent to “email c.”

Here is the contact form:

[code]
Please fill in all fields. We respect your privacy and will never use your information for any other purpose than to reply to your inquiry. You will not be added to any mailing lists.



        <span class="style1">First &amp; Last Name </span><span class="style1"><br>
         </span>
        <input type="text" name="firstlast" size="40" />
        
        <br /> 
                   
        <span class="style1">Address:</span><br> 
        <input type="text" name="address" size="40" />

        <br />
        
        <span class="style1">City</span>:<br> 
        <input type="text" name="city" size="25" />&nbsp;&nbsp;
        <span class="style1">State</span>:<input type="text" name="state" size="2" />
        &nbsp;&nbsp;
        <span class="style1">Zip: </span> <input type="text" name="zipcode" size="5" />
        <br />
       
                   
         <span class="style1">E-mail address </span><span class="style1"></span><br>
        <input type="text" name="email" size="40" />
       
        <br />
        <span class="style1">Phone</span><br>
        <input type="text" name="phone" size="40" />
        <br />
       
       <span class="style1">Please select the area you are inquiring about</span><br>
        <select name="subject" size="1" class="style2">
        
          <option value="1">Landscaping</option>
          <option value="2">Sitework</option>
          <option value="3">Employment</option>
        </select>
        <br /><br />
        <span class="style1">Briefly explain what you are looking for</span>
    <br />
    <textarea name="summary" cols="40" rows="8"></textarea><br /><br />
        <input name="submit2" type="submit" class="style2" value="Send" />

        <input name="reset2" type="reset" class="style2" value="Reset" />
      </form>

[/code]

And here is the php code I tried that clearly did not work. Can someone please help?

[php] if ($_POST[’$subject’]==“value 1”)

{
[email protected];

else if ($_POST[’$subject’]==“value 2”)
{

[email protected];

 else if ($_POST['$subject']=="value 3")

{
[email protected];

}

$firstlast = $_POST[‘firstlast’];
$email = $_POST[‘email’];
$address = $_POST[‘address’];
$city = $_POST[‘city’];
$phone = $_POST[‘phone’];
$subject = $_POST[‘subject’];
$summary = $_POST[‘summary’];
$totalmessage= "
Name: $firstlast \n
Email: $email \n
Subject: $subject \n
Address: $address \n
City: $city \n
Phone: $phone \n
Summary: $summary \n";

$messages = array();

Allow only reasonable real names

if (!preg_match("/^[\w\ +-’"]+$/", $firstlast)) {
$messages[] = "The name field must contain only " .
"alphabetical characters, numbers, spaces, and " .
“reasonable punctuation. We apologize for any inconvenience.”;
}

Allow only reasonable email addresses

if (!preg_match("/^[\w+-.~]+@[-\w.!]+$/", $email)) {
$messages[] = “That is not a valid email address.”;
}

$summary = $_POST[‘summary’];

Make sure the message has a body

if (preg_match(’/^\s*$/’, $summary)) {
$messages[] = “Your comment was blank. Did you mean to say " .
“something?”;
}
if (count($messages)) {
# There were problems, so tell the user and
# don’t send the message yet
foreach ($messages as $message) {
echo(”

$message

\n");
}
echo("

Click the back button and correct the problems. " .
“Then click Send Your Message again.

”);
} else {
# Send the email - we’re done
mail($recipient,
$firstlast,
$totalmessage,
“From: $firstlast <$email>\r\n” .
“Reply-To: $firstlast <$email>\r\n”);
echo(“

Your message has been sent. Thank you! Hit the back button to return to site.

\n”);
}

?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service