Jump to content

Sending to an email address based on menu selection


muchomacho

Recommended Posts

Hello everyone,

How can I send form results to an email address based on what the user selects from a menu?

Here's the HTML code:

[code]
<select name="Company" onChange="redirect(this.options.selectedIndex)" size="1" onFocus="this.style.background='#fff';" onBlur="this.style.background='#F8E2C9';" class="text" style="width:170px;" value="0">
<option selected>- Select Company -</option>
<option value="a" selected>A</option>
<option value="b">B</option>
<option value="c">C</option>
</select>

[/code]

Here's PHP code to send email:

[code]
//Sending Email to form owner
$pfw_header = "From: $Email\n"
  . "Reply-To: $Email\n";
$pfw_subject = "Job Application";
$pfw_email_to = "someone@abc.com";
$pfw_message = "Company: $Company\n\n"
. "First Name: $FirstName\n\n"
. "Middle Initial: $MiddleInitial\n\n"
. "Last Name: $LastName\n\n"
. "Address: $StreetName\n\n"
. "City: $City\n\n"
. "State: $State\n\n"
. "Zip Code: $ZipCode\n\n"
. "Phone: $Phone\n\n"
. "Best Time to Call: $BestTimetoCall\n\n"
. "Email: $Email\n\n"
. "High School: $HighSchool\n\n"
. "College: $College\n\n"
. "Resume: $resume_URL\n\n"
. "How Did You Find Us: $HowDidYouFindUs\n\n"
. "Referral Name: $ReferralName\n\n"
. "Race Ethnic Origin: $RaceEthnicOrigin\n\n"
. "Vietnam Veteran: $VietnamVeteran\n\n"
. "Decline: $Decline\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
[/code]

Any help will be appreciated.

Thanks
Link to comment
Share on other sites

You could try something like this...

[code]

<?php

$recipient = $_POST['company'];

switch ($recipient) {

default:
//send email to webmaster
$toaddress = "webmaster@mysite.com";
break;

case "company1":
//send email to person1@somewhere.com
$toaddress = "person1@somewhere.com";
break;

case "company2":
//send email to person2@somewhereelse.com
$toaddress = "person2@somewhereelse.com";
break;

}

FunctionToMail($toaddress, $fromaddress, $sub);

//Here follows some pseudocode for the function

function FunctionToMail($to, $from, $subject) {

//Enter in the email script here that accepts the above variables as input

}

?>

[/code]

Link to comment
Share on other sites

I'd be inclined to save it in an array keyed on company name if there's only a couple, or a database if theirs lots.

[code]<?php
$email_addresses = array('CompanyA' => "me@mycompany.com", 'CompanyB' => "you@yourcompany.com");

$to = $email_address['$_REQUEST['Company']'];
?>[/code]

Regards
Huggie
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.