Jump to content


Photo

Sending to an email address based on menu selection


  • Please log in to reply
7 replies to this topic

#1 muchomacho

muchomacho
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 23 October 2006 - 03:48 PM

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:

<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>


Here's PHP code to send email:

//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 ) ;

Any help will be appreciated.

Thanks

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 23 October 2006 - 03:51 PM

Where are you storing the email addresses?

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 muchomacho

muchomacho
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 23 October 2006 - 03:54 PM

Hi,

I am not planning to store any email address. When the user submits the form it'll go to whatever email or company selected.

Thanks

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 23 October 2006 - 03:59 PM

That's impossible, you must have the email addresses somewhere...

If I select Company A from your drop down, how does the form know that Company A's email address is me@company.com?

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 muchomacho

muchomacho
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 23 October 2006 - 04:07 PM

I am very sorry, I've totally misunderstood your last question therefore my last reply was totally wrong. I am not sure if I should store them in the menu or this should be differents variable? This is where I am totally clueless. Maybe you can help.

Thanks again.

#6 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 23 October 2006 - 04:12 PM

You could try something like this...


<?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

}

?>




#7 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 23 October 2006 - 04:19 PM

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.

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

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

Regards
Huggie

Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#8 muchomacho

muchomacho
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 23 October 2006 - 04:52 PM

Thanks a million! It worked great.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users