php email contact form with 2 dropdown box for different email addresses

I have 2 drop downs that will ultimately send an email to different addresses. I have this built right now with the if else statements for the request dropdown, but need to have the condition for different addresses for the property dropdown.

First dropdown selects a property and the second selects the type of request.

Each address has different email addresses per the request selected.

Can any one help me solve this?
submit.php
form.html
javahutAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
hieloConnect With a Mentor Commented:
Glad everything is working.

Regards,
Hielo
0
 
hieloCommented:

...
if($address=="COMMERCIAL_715_W_Fairchild")  $emailaddress="me@domain.com";
elseif($address=="COMMERCIAL_Plaza_31") $emailaddress = "you@domain.com";
elseif ($Request == "General_Maintenance")  $emailaddress="me@domain.com";
elseif ($Request == "Heat_Air") $emailaddress = "you@domain.com";
elseif ($Request == "Electrical") $emailaddress = "me@domain.com";
elseif ($Request == "Plumbing") $emailaddress = "you@domain.com,me@domain.com";
elseif ($Request == "Telephone_Data") $emailaddress = "them@domain.com";
elseif ($Request == "Clogged_Drain") $emailaddress = "somemore@domain.com,me@domain.com";
elseif ($Request == "Trash_Rubbish") $emailaddress = "me@domain.com";
elseif ($Request == "Pylon_Signage") $emailaddress = "allofus@domain.com";
elseif ($Request == "Interior_Design") $emailaddress = "me@domain.com";
else {exit;}
 ...

Open in new window

0
 
javahutAuthor Commented:
Looking at it.
Looks like the 2 dropdowns have been combined. What I need is to have the first property have a list of addresses that are different then the second property.

Example:
COMMERCIAL_715_W_Fairchild
"General_Maintenance")  $emailaddress="me@domain.com";
"Heat_Air")  $emailaddress="you@domain.com";
"Electrical")  $emailaddress="them@domain.com";


COMMERCIAL_Plaza_31
"General_Maintenance")  $emailaddress="abc@domain.com";
"Heat_Air")  $emailaddress="def@domain.com";
"Electrical")  $emailaddress="ghi@domain.com";


0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
hieloCommented:

<?php
$subject = "Maintenance Request" . " - " . $_POST['Request_Last_Name'] . ", " . $_POST['Request_First_Name'];
$name =  $_POST['Request_First_Name'] . " " . $_POST['Request_Last_Name'];
$address =  $_POST['Request_Building_Location'];


$aptnumber =  $_POST['Request_Appartment_Number'];
$phone =  $_POST['Request_Day_Phone'];
$phone2 =  $_POST['Request_Phone2'] . " (secondary phone)";
$email = $_POST["email"];
$description =  $_POST['Request_Description'];
$Request = $_POST["Request"];
 

$sentTo=['COMMERCIAL_715_W_Fairchild']=array(); 
$sentTo=['COMMERCIAL_715_W_Fairchild']['General_Maintenance']='me@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Heat_Air']='you@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Electrical']='me@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Plumbing']='you@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Telephone_Data']='me@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Clogged_Drain']='you@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Trash_Rubbish']='me@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Pylon_Signage']='you@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Interior_Design']='me@domain.com';


$sentTo=['COMMERCIAL_Plaza_31']=array(); 
$sentTo=['COMMERCIAL_Plaza_31']['General_Maintenance']='me@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Heat_Air']='you@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Electrical']='me@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Plumbing']='you@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Telephone_Data']='me@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Clogged_Drain']='you@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Trash_Rubbish']='me@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Pylon_Signage']='you@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Interior_Design']='me@domain.com';


if( !isset($sentTo[$address][$Request]) || empty($sentTo[$address][$Request]) )
{
	exit;
}
else
{
	$emailaddress=$sentTo[$address][$Request];
}
// validation
		$validationOK=true;
		if (Trim($email)=="") $validationOK=false;
		if (!$validationOK) {
		  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
		  exit;
		}
		$body = "From: $name\nAddress: $address     $aptnumber\n\nPhone: $phone\nPhone: $phone2\nE-Mail: $email\n\nRequested Service:\n$Request\n\n\nThe following information notes about requested service:\n$description\n ";
		
		$success = mail($emailaddress,$subject,$body,"From: <$email>");

		if ($success){
		  print "<meta http-equiv=\"refresh\" content=\"0;URL=thank_you.html\">";
		}
		else{
		  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
		}

?>

Open in new window

0
 
javahutAuthor Commented:
Didn't work. Tried to switch out the 2 general requests with some valid emails and the form got hung up and didn't end on the thank you page.

Other ideas?
0
 
hieloCommented:
based on my previous post, on line 38 put:
echo "I will be sending the data to: " . $sentTo[$address][$Request];

What's the output?
0
 
javahutAuthor Commented:
I am pretty new to php, so I am not sure what you mean by the output.
0
 
hieloCommented:
>>I am pretty new to php, so I am not sure what you mean by the output.
I meant, after you make the suggested addition on line 38, resubmit your form. What do you see no the browser.

By the way, to troubleshoot this problem, just for now, also
change these:
if ($success){
                  print "<meta http-equiv=\"refresh\" content=\"0;URL=thank_you.html\">";
                }
                else{
                  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
                }


to:
/*
                if ($success){
                  print "<meta http-equiv=\"refresh\" content=\"0;URL=thank_you.html\">";
                }
                else{
                  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
                }
*/

Open in new window

0
 
javahutAuthor Commented:
The output on the echo (sorry didn't get what you had meant at first) didn't come back, still is hanging up.

I added the echo and also commented out the if else statement for the redirect.

Still is not sending off an email.
0
 
hieloCommented:
try this. Let me know what's the ouput:
<?php
$subject = "Maintenance Request" . " - " . $_POST['Request_Last_Name'] . ", " . $_POST['Request_First_Name'];
$name =  $_POST['Request_First_Name'] . " " . $_POST['Request_Last_Name'];
$address =  $_POST['Request_Building_Location'];


$aptnumber =  $_POST['Request_Appartment_Number'];
$phone =  $_POST['Request_Day_Phone'];
$phone2 =  $_POST['Request_Phone2'] . " (secondary phone)";
$email = $_POST["email"];
$description =  $_POST['Request_Description'];
$Request = $_POST["Request"];
 /*
if ($Request == "General_Maintenance")  $emailaddress="me@domain.com";
elseif ($Request == "Heat_Air") $emailaddress = "you@domain.com";
elseif ($Request == "Electrical") $emailaddress = "me@domain.com";
elseif ($Request == "Plumbing") $emailaddress = "you@domain.com,me@domain.com";
elseif ($Request == "Telephone_Data") $emailaddress = "them@domain.com";
elseif ($Request == "Clogged_Drain") $emailaddress = "somemore@domain.com,me@domain.com";
elseif ($Request == "Trash_Rubbish") $emailaddress = "me@domain.com";
elseif ($Request == "Pylon_Signage") $emailaddress = "allofus@domain.com";
elseif ($Request == "Interior_Design") $emailaddress = "me@domain.com";
else {exit;}
 */

$sentTo=['COMMERCIAL_715_W_Fairchild']=array(); 
$sentTo=['COMMERCIAL_715_W_Fairchild']['General_Maintenance']='me@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Heat_Air']='you@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Electrical']='me@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Plumbing']='you@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Telephone_Data']='me@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Clogged_Drain']='you@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Trash_Rubbish']='me@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Pylon_Signage']='you@domain.com';
$sentTo=['COMMERCIAL_715_W_Fairchild']['Interior_Design']='me@domain.com';


$sentTo=['COMMERCIAL_Plaza_31']=array(); 
$sentTo=['COMMERCIAL_Plaza_31']['General_Maintenance']='me@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Heat_Air']='you@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Electrical']='me@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Plumbing']='you@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Telephone_Data']='me@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Clogged_Drain']='you@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Trash_Rubbish']='me@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Pylon_Signage']='you@domain.com';
$sentTo=['COMMERCIAL_Plaza_31']['Interior_Design']='me@domain.com';

echo "<pre>" . print_r($_POST,true) . "</pre>";

if( !isset($sentTo[$address][$Request]) || empty($sentTo[$address][$Request]) )
{
        die("Unable to determine email recipient");
	   //exit;
}
else
{
        $emailaddress=$sentTo[$address][$Request];
}

echo "attempting to send email to  $emailaddress";
// validation
		$validationOK=true;
		if (Trim($email)=="") $validationOK=false;
		if (!$validationOK) {
		  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
		  exit;
		}
		$body = "From: $name\nAddress: $address     $aptnumber\n\nPhone: $phone\nPhone: $phone2\nE-Mail: $email\n\nRequested Service:\n$Request\n\n\nThe following information notes about requested service:\n$description\n ";
		
		$success = mail($emailaddress,$subject,$body,"From: <$email>");
/*
		if ($success){
		  print "<meta http-equiv=\"refresh\" content=\"0;URL=thank_you.html\">";
		}
		else{
		  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
		}
*/

?>

Open in new window

0
 
javahutAuthor Commented:
Nothing... Did not see anything. Same as before.

I reloaded the original version just to see if anything was funky from the else if statement and that did submit. I put it back to the last version you supplied and tried again and it hung up on the submit.php.

Would simplifying this to just the email and 2 drop downs make this easier to tackle? We could even keep the 2 arrays to just General_Maintenance and Heat_Air. That there will be less code to work with.
0
 
hieloCommented:
javahut, my apologies. Upon closer inspection, I have:
$sentTo=[...

that equal sign should not be there at all:
$sentTo[....
<?php
$subject = "Maintenance Request" . " - " . $_POST['Request_Last_Name'] . ", " . $_POST['Request_First_Name'];
$name =  $_POST['Request_First_Name'] . " " . $_POST['Request_Last_Name'];
$address =  $_POST['Request_Building_Location'];


$aptnumber =  $_POST['Request_Appartment_Number'];
$phone =  $_POST['Request_Day_Phone'];
$phone2 =  $_POST['Request_Phone2'] . " (secondary phone)";
$email = $_POST["email"];
$description =  $_POST['Request_Description'];
$Request = $_POST["Request"];
 /*
if ($Request == "General_Maintenance")  $emailaddress="me@domain.com";
elseif ($Request == "Heat_Air") $emailaddress = "you@domain.com";
elseif ($Request == "Electrical") $emailaddress = "me@domain.com";
elseif ($Request == "Plumbing") $emailaddress = "you@domain.com,me@domain.com";
elseif ($Request == "Telephone_Data") $emailaddress = "them@domain.com";
elseif ($Request == "Clogged_Drain") $emailaddress = "somemore@domain.com,me@domain.com";
elseif ($Request == "Trash_Rubbish") $emailaddress = "me@domain.com";
elseif ($Request == "Pylon_Signage") $emailaddress = "allofus@domain.com";
elseif ($Request == "Interior_Design") $emailaddress = "me@domain.com";
else {exit;}
 */

$sentTo['COMMERCIAL_715_W_Fairchild']=array(); 
$sentTo['COMMERCIAL_715_W_Fairchild']['General_Maintenance']='me@domain.com';
$sentTo['COMMERCIAL_715_W_Fairchild']['Heat_Air']='you@domain.com';
$sentTo['COMMERCIAL_715_W_Fairchild']['Electrical']='me@domain.com';
$sentTo['COMMERCIAL_715_W_Fairchild']['Plumbing']='you@domain.com';
$sentTo['COMMERCIAL_715_W_Fairchild']['Telephone_Data']='me@domain.com';
$sentTo['COMMERCIAL_715_W_Fairchild']['Clogged_Drain']='you@domain.com';
$sentTo['COMMERCIAL_715_W_Fairchild']['Trash_Rubbish']='me@domain.com';
$sentTo['COMMERCIAL_715_W_Fairchild']['Pylon_Signage']='you@domain.com';
$sentTo['COMMERCIAL_715_W_Fairchild']['Interior_Design']='me@domain.com';


$sentTo['COMMERCIAL_Plaza_31']=array(); 
$sentTo['COMMERCIAL_Plaza_31']['General_Maintenance']='me@domain.com';
$sentTo['COMMERCIAL_Plaza_31']['Heat_Air']='you@domain.com';
$sentTo['COMMERCIAL_Plaza_31']['Electrical']='me@domain.com';
$sentTo['COMMERCIAL_Plaza_31']['Plumbing']='you@domain.com';
$sentTo['COMMERCIAL_Plaza_31']['Telephone_Data']='me@domain.com';
$sentTo['COMMERCIAL_Plaza_31']['Clogged_Drain']='you@domain.com';
$sentTo['COMMERCIAL_Plaza_31']['Trash_Rubbish']='me@domain.com';
$sentTo['COMMERCIAL_Plaza_31']['Pylon_Signage']='you@domain.com';
$sentTo['COMMERCIAL_Plaza_31']['Interior_Design']='me@domain.com';

echo "<pre>" . print_r($_POST,true) . "</pre>";

if( !isset($sentTo[$address][$Request]) || empty($sentTo[$address][$Request]) )
{
        die("Unable to determine email recipient");
	   //exit;
}
else
{
        $emailaddress=$sentTo[$address][$Request];
}

echo "attempting to send email to  $emailaddress";
// validation
		$validationOK=true;
		if (Trim($email)=="") $validationOK=false;
		if (!$validationOK) {
		  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
		  exit;
		}
		$body = "From: $name\nAddress: $address     $aptnumber\n\nPhone: $phone\nPhone: $phone2\nE-Mail: $email\n\nRequested Service:\n$Request\n\n\nThe following information notes about requested service:\n$description\n ";
		
		//$success = mail($emailaddress,$subject,$body,"From: <$email>");
/*
		if ($success){
		  print "<meta http-equiv=\"refresh\" content=\"0;URL=thank_you.html\">";
		}
		else{
		  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
		}
*/

?>

Open in new window

0
 
javahutAuthor Commented:
You are awesome...!

Removing the equal sign did the trick. I uncommented and changed everything back to the exit and validation and the form submits perfectly.

I just got done testing it, and it is exactly what needed to happen. No need to apologize on the equal sign. Looking at code all day... sometimes things look right. Done that myself many a times.

Thank you very much.
-javahut
0
 
javahutAuthor Commented:
worked trough the problem and found the solution I was looking for.
0
All Courses

From novice to tech pro — start learning today.