I am trying to modify a form so that a different recipient is chosen based on a drop-down box selection. I'm sure it's just me, but I feel like I'm breaking my brain trying to figure this out.
The basic form fields are Name, Email, Subject, Subject Matter, and Comments. Name, Email, and Subject are user-inputable text boxes, Subject Matter is the drop-down box, and Comments is a textarea.
What I want is for the user to select from the drop down box, and based on their selection, the email will go to a different address.
ie: User selects subject matter 'A', email goes to a@a.com. User selects subject matter 'B', email goes to b@b.com.
How would I do this using process.php?
Thanks in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In the process.php you will find a line that starts with "mail(".
just above this line put in something like this:
if($a=="a"){
mail("a@a.com",...
Then just below end the if statement with a close bracket
}
Copy these lines and paste below and change the if statement to something like:
else if($a=="b"){
mail("b@b.com",...
}
else {
mail("a@a.com",...
}
Without details of the process.php I can not be too specific but you should get the general idea. If you still need help come back and post again.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Having a bit of trouble figuring out where exactly to put the lines you mentioned; I got a syntax error when I placed where I thought it ought to go. Here's the edited version of process.php before adding the above...Any help is greatly appreciated, and I thank you so much for being willing to help those of us who aren't so familiar with php.
<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','Name');
pt_register('POST','Email');
pt_register('POST','Subject');
pt_register('POST','Department');
pt_register('POST','Comments');
$Comments=preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $Comments);if($Name=="" || $Email=="" || $Subject=="" || $Department=="" || $Comments=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Name: ".$Name."
Email: ".$Email."
Subject: ".$Subject."
Department: ".$Department."
Comments: ".$Comments."
";
$message = stripslashes($message);
mail("a@a.com","$Subject",$message,"$Email");
You still have to fill in the blanks but here it is:
<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','Name');
pt_register('POST','Email');
pt_register('POST','Subject');
pt_register('POST','Department');
pt_register('POST','Comments');
$Comments=preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $Comments);
if($Name=="" || $Email=="" || $Subject=="" || $Department=="" || $Comments=="" ){ $errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again."; }
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NA
ME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Name: ".$Name."
Email: ".$Email."
Subject: ".$Subject."
Department: ".$Department."
Comments: ".$Comments."
";
$message = stripslashes($message);
if($Department=="FILL_IN_THE_BLANK") {
// First case email according to first department selection
mail("a@a.com","$Subject",$message,"$Email");
} else if($Department=="FILL_IN_THE_BLANK") {
// Second case email according to second department selection
mail("b@b.com","$Subject",$message,"$Email");
} else {
// Third case is the default in case of any mixup in the department selection
mail("a@a.com","$Subject",$message,"$Email");
}
I am trying to modify a form so that a different recipient is chosen based on a drop-down box selection. I'm sure it's just me, but I feel like I'm breaking my brain trying to figure this out.
The basic form fields are Name, Email, Subject, Subject Matter, and Comments. Name, Email, and Subject are user-inputable text boxes, Subject Matter is the drop-down box, and Comments is a textarea.
What I want is for the user to select from the drop down box, and based on their selection, the email will go to a different address.
ie: User selects subject matter 'A', email goes to a@a.com. User selects subject matter 'B', email goes to b@b.com.
How would I do this using process.php?
Thanks in advance.
In the process.php you will find a line that starts with "mail(".
just above this line put in something like this:
if($a=="a"){
mail("a@a.com",...
Then just below end the if statement with a close bracket
}
Copy these lines and paste below and change the if statement to something like:
else if($a=="b"){
mail("b@b.com",...
}
else {
mail("a@a.com",...
}
Without details of the process.php I can not be too specific but you should get the general idea. If you still need help come back and post again.
Having a bit of trouble figuring out where exactly to put the lines you mentioned; I got a syntax error when I placed where I thought it ought to go. Here's the edited version of process.php before adding the above...Any help is greatly appreciated, and I thank you so much for being willing to help those of us who aren't so familiar with php.
<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','Name');
pt_register('POST','Email');
pt_register('POST','Subject');
pt_register('POST','Department');
pt_register('POST','Comments');
$Comments=preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $Comments);if($Name=="" || $Email=="" || $Subject=="" || $Department=="" || $Comments=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Name: ".$Name."
Email: ".$Email."
Subject: ".$Subject."
Department: ".$Department."
Comments: ".$Comments."
";
$message = stripslashes($message);
mail("a@a.com","$Subject",$message,"$Email");
header("Refresh: 0;url=thanks.html");
?><?php
}
?>
You still have to fill in the blanks but here it is:
<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','Name');
pt_register('POST','Email');
pt_register('POST','Subject');
pt_register('POST','Department');
pt_register('POST','Comments');
$Comments=preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $Comments);
if($Name=="" || $Email=="" || $Subject=="" || $Department=="" || $Comments=="" ){ $errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again."; }
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NA
ME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Name: ".$Name."
Email: ".$Email."
Subject: ".$Subject."
Department: ".$Department."
Comments: ".$Comments."
";
$message = stripslashes($message);
if($Department=="FILL_IN_THE_BLANK") {
// First case email according to first department selection
mail("a@a.com","$Subject",$message,"$Email");
} else if($Department=="FILL_IN_THE_BLANK") {
// Second case email according to second department selection
mail("b@b.com","$Subject",$message,"$Email");
} else {
// Third case is the default in case of any mixup in the department selection
mail("a@a.com","$Subject",$message,"$Email");
}
header("Refresh: 0;url=thanks.html");
?><?php
}
?>