One contact form but two email addresses

  ade.h 00:11 27 Aug 06
Locked

Is it possible to configure a PHP file to send the message to a particular address from a choice of two, based on the selection from a drop-down box on the form?
ie. the site visitor selects option A and their message goes to address Y; select B and the message goes to Z.
I thought this might be possible with an if command of some kind. If it's not possible, that's not the end of the world, but it would save having two seperate forms when only the subject matter is unique to each.

  De Marcus™ 01:52 27 Aug 06

I asked a friend of mine the same thing on MSN recently (that's the reason for the formatting below) and this is what he told me:


raul says:
well
raul says:
it will be lilke this
raul says:
it will create a form
raul says:
that will contain a drop-down, and a textbox ( for the message )
raul says:
in the text box he writes the message
raul says:
selects something from the drop-down, like A or B, or what ever you want in there
raul says:
and click, click on a submit button
raul says:
the submit will re-direct him to another page
raul says:
it will be like this
raul says:
<form method='post' action='a_form.php'>
raul says:
and will direct him to the a_form.php file
raul says:
and, in there, it will be like this :
raul says:
$drop_down = $_POST["drop_down"]; ( where drop_down is the name of the drop down element.. it can have a diferent name )
raul says:
$message = $_POST["message"]; ( the message is the name of the textbox where he writes the message... of course,it can have a diferent name)
raul says:
and then
raul says:
if ($drop_down=="A")
raul says:
{
raul says:
// here you write the code that will email the message to an address
raul says:
}
raul says:
else
raul says:
if ($drop_down=="B")
raul says:
{
raul says:
// here you write the code that wiill email the message to another email address
raul says:
}
raul says:
and so on


I haven't had a chance to test it yet.

  De Marcus™ 01:54 27 Aug 06

Just incase, I have his permission to post the conversation extract. :-)

  harristweed 08:43 27 Aug 06

<?php
if($dropdown==1)
{
$email="[email protected]";
}else{
$email="[email protected]";
}
$mail_message="load of stuff from form.";

$subject = "Answer to question on PCA forum";

$headers .= "From: [email protected]\n";
$headers .= "X-Priority: 2\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";

if(mail($email, $subject, $mail_message, $headers));

  ade.h 16:07 27 Aug 06

Nice stuff. Thanks to both of you. I will try that when I get the time and mark as resolved if it works. It looks like it will do the job.

  ade.h 18:05 27 Aug 06

Hmmm, that jut got a parse error. I wasn't 100% sure where to place which bit of code, and I obviously guessed wrongly. I've set out the original functioning code below; would you be able to tell me which bit of code to use and where? It's the servicetype field that needs to influence which email address is used.

<?php
$badStrings = array("Content-Type:",
"MIME-Version:",
"Content-Transfer-Encoding:",
"bcc:",
"cc:");
foreach($_POST as $k => $v){
foreach($badStrings as $v2){
if(strpos($v, $v2) !== false){
header("HTTP/1.0 403 Forbidden");
exit;
}}}
foreach($_GET as $k => $v){
foreach($badStrings as $v2){
if(strpos($v, $v2) !== false){
header("HTTP/1.0 403 Forbidden");
exit;
}}}
?>
<?
$title = $_POST[title] ;
$name = $_POST[name] ;
$email = $_POST[email] ;
$phone = $_POST[phone] ;
$location = $_POST[location] ;
$clienttype = $_POST[clienttype] ;
$businessname = $_POST[businessname] ;
$servicetype = $_POST[servicetype] ;
$weburl = $_POST[weburl] ;
$message = $_POST[message] ;

if (!isset($_REQUEST[email])) {
header( "Location: http: // www . url .com /contactus.html" );
}
elseif (empty($name) || empty($email) || empty($message)) {
header( "Location: http: // www . url .com /error1.html" );
}
else {
$mail_message="From: $name
";
$mail_message.="Phone: $phone
";
$mail_message.="Location: $location
";
$mail_message.="Client Type: $clienttype
";
$mail_message.="Business Name: $businessname
";
$mail_message.="Type of service: $servicetype
";
$mail_message.="Website URL: $weburl
";
$mail_message.="$message";

mail( "info @ domain.com", "Form Message",
$mail_message, "From: $name <$email>" );
header( "Location: http: // www . url .com /success.html" );
}
?>

  harristweed 09:26 28 Aug 06

<?php
$badStrings = array("Content-Type:",
"MIME-Version:",
"Content-Transfer-Encoding:",
"bcc:",
"cc:");
foreach($_POST as $k => $v){
foreach($badStrings as $v2){
if(strpos($v, $v2) !== false){
header("HTTP/1.0 403 Forbidden");
exit;
}}}
foreach($_GET as $k => $v){
foreach($badStrings as $v2){
if(strpos($v, $v2) !== false){
header("HTTP/1.0 403 Forbidden");
exit;
}}}
?>
<?
$title = $_POST[title] ;
$name = $_POST[name] ;
$email = $_POST[email] ;
$phone = $_POST[phone] ;
$location = $_POST[location] ;
$clienttype = $_POST[clienttype] ;
$businessname = $_POST[businessname] ;
$servicetype = $_POST[servicetype] ;
$weburl = $_POST[weburl] ;
$message = $_POST[message] ;

if (!isset($_REQUEST[email])) {
header( "Location: http: // www . url .com /contactus.html" );
}
elseif (empty($name) || empty($email) || empty($message)) {
header( "Location: http: // www . url .com /error1.html" );
}
else {
$mail_message="From: $name
";
$mail_message.="Phone: $phone
";
$mail_message.="Location: $location
";
$mail_message.="Client Type: $clienttype
";
$mail_message.="Business Name: $businessname
";
$mail_message.="Type of service: $servicetype
";
$mail_message.="Website URL: $weburl
";
$mail_message.="$message";
// start of new stff
if($dropdown==1)
{
$to_email="[email protected]";
}else{
$to_email="[email protected]";
}

mail( "$to_email", "Form Message", $mail_message, "From: $name <$email>" );
// end of new stuff
header( "Location: http: // www . url .com /success.html" );
}
?>

  ade.h 16:01 28 Aug 06

Nice one! It works perfectly. Thank very much for helping me out with this one.

Thanks to De Marcus, too.

This thread is now locked and can not be replied to.

Surface Pro (2017) vs Surface Pro 4

20 groundbreaking 3D animation technologies coming to Siggraph 2017

iPad Pro 12.9 vs Surface Pro 5