Jump to content

Email sent depending on option (from drop down) selected in form ...


prettikittie

Recommended Posts

Hi,

 

I do hope it's alright to begin another topic as this is different then my last issue (though resolved!).

 

Think maybe I'm getting in a bit over my head here?! Lol

 

In my form, I've a drop down menu with 5 different city locations ... I need to be able and send an email based on the city selected.

 

For example:

 

If they were to select Orange Grove, then I need the email to be sent to [email protected]

 

If they select Mathis, I need the email to go to [email protected] and so on ...

 

The following is what I have currently ... but I'm not clear on how to implement what I need done and can't seem to find anything via Google or such. (Hard to know what to type and search as well.)

 

Thank you`

 

<?php

$EmailFrom = "$Name";
$EmailTo = "xxx";
$Subject = "xxx";
$locations= htmlspecialchars(Trim(stripslashes($_POST['Locations'])));
$Name = htmlspecialchars(Trim(stripslashes($_POST['Name']))); 
$Phone = htmlspecialchars(Trim(stripslashes($_POST['Phone']))); 
$Email = htmlspecialchars(Trim(stripslashes($_POST['Email']))); 
$Message = htmlspecialchars(Trim(stripslashes($_POST['Message']))); 

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Location: ";
$Body .= $Locations;
$Body .= "\n";
$Body .= "Request: ";
$Body .= $Request;
$Body .= "\n";


// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

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

Most of the code is good, there were a few problems:

 

if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

 

You have to change some of those double quotes. So:

 

if (!$validationOK) {
  print '<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">';
  exit;
}

 

Same goes for the other meta redirects.

 

Now for the email problem, simply do this:

 

$EmailTo = str_replace(' ', '', strtolower($_POST['Locations'])) . '@' . str_replace(' ', '', strtolower($_POST['Locations'])) . '.com';

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.