Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Email sent depends on drop down option selected - help ...
Old 07-16-2009, 04:40 PM Email sent depends on drop down option selected - help ...
Novice Talker

Posts: 10
Name: Jennifer
Trades: 0
Hi,

My apologies if this is already posted, I've searched everywhere (google, etc) but just can't seem to get it right.

My form has a drop down in it where people may select a city ... and each city has it's own email.

For example:

If city 'Mathis' is selected, then an email will go to x@mathis.com
If city 'Orange Grove' is selected, then an email will go to x@orangegrove.com

and so on ...

Below is where I'm at with he form, but I can't get this to work.

I'd really appreciate any help with this, thank you so much ...

Code:
  1. <?php
  2. $EmailFrom = "xxx";
  3. $EmailTo = "xxx";
  4. if (Locations===Marthis) {
  5. mailto = "x@mathis.com";
  6. } else if (Locations===Orange Grove) {
  7. mailto = "x@og.com";
  8. }
  9. $Subject = "Customer Request";
  10. $locations= htmlspecialchars(Trim(stripslashes($_POST['Locations'])));
  11. $Name = htmlspecialchars(Trim(stripslashes($_POST['Name'])));
  12. $Phone = htmlspecialchars(Trim(stripslashes($_POST['Phone'])));
  13. $Email = htmlspecialchars(Trim(stripslashes($_POST['Email'])));
  14. $Message = htmlspecialchars(Trim(stripslashes($_POST['Message'])));
  15. // validation
  16. $validationOK=true;
  17. if (!$validationOK) {
  18. print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  19. exit;
  20. }
  21. // prepare email body text
  22. $Body = "";
  23. $Body .= "Name: ";
  24. $Body .= $Name;
  25. $Body .= "\n";
  26. $Body .= "Phone: ";
  27. $Body .= $Phone;
  28. $Body .= "\n";
  29. $Body .= "Email: ";
  30. $Body .= $Email;
  31. $Body .= "\n";
  32. $Body .= "Location: ";
  33. $Body .= $Locations;
  34. $Body .= "\n";
  35. $Body .= "Request: ";
  36. $Body .= $Request;
  37. $Body .= "\n";
  38. // send email
  39. $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
  40. // redirect to success page
  41. if ($success){
  42. print "<meta http-equiv=\"refresh\" content=\"0;URL=submit.htm\">";
  43. }
  44. else{
  45. print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  46. }
  47. ?>
Jennifer ~
jennifer420 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-16-2009, 04:51 PM Re: Email sent depends on drop down option selected - help ...
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Oh, pretty, pretty please go get some elementary training in coding in PHP. You're going to get yourself in trouble with such coding.

A couple of pointers:

1) Assume case matters! "locations" is not always equal to "Locations".
2) Learn what a variable is and then learn what a constant is. You won't be leaving "$" symbols missing anymore.

I could give you more suggestions, but the most important is to go learn before you create something live!

Here's adjusted code:

PHP Code:
<?php
$locations_to_emails 
= array('Mathis'=>'mathis@mydomain.com',
                             
'Orange Grove'=>'orange_grove@mydomain.com'
                            
);
$Subject "Customer Request";
$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'])));

$EmailFrom "xxx";
$EmailTo = isset($locations_to_emails[$Locations])?$locations_to_emails[$Locations]:'YOUR_DEFAULT_EMAIL_ADDRESS';

// 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=submit.htm\">";
}
else{
  print 
"<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 07-16-2009, 05:02 PM Re: Email sent depends on drop down option selected - help ...
Novice Talker

Posts: 10
Name: Jennifer
Trades: 0
Quote:
Originally Posted by JeremyMiller View Post
Oh, pretty, pretty please go get some elementary training in coding in PHP. You're going to get yourself in trouble with such coding.

A couple of pointers:

1) Assume case matters! "locations" is not always equal to "Locations".
2) Learn what a variable is and then learn what a constant is. You won't be leaving "$" symbols missing anymore.

I could give you more suggestions, but the most important is to go learn before you create something live!

Here's adjusted code:

PHP Code:
<?php
$locations_to_emails 
= array('Mathis'=>'mathis@mydomain.com',
                             
'Orange Grove'=>'orange_grove@mydomain.com'
                            
);
$Subject "Customer Request";
$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'])));

$EmailFrom "xxx";
$EmailTo = isset($locations_to_emails[$Locations])?$locations_to_emails[$Locations]:'YOUR_DEFAULT_EMAIL_ADDRESS';

// 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=submit.htm\">";
}
else{
  print 
"<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
Learning = screwing up.

How are we supposed to continue learning without practicing and/or asking questions?

I'm assuming you knew it all before ever starting then ...
jennifer420 is offline
Reply With Quote
View Public Profile
 
Old 07-16-2009, 05:32 PM Re: Email sent depends on drop down option selected - help ...
orionoreo's Avatar
Ultra Talker

Posts: 335
Name: Jerry
Trades: 0
Quote:
Originally Posted by jennifer420 View Post
How are we supposed to continue learning without practicing and/or asking questions?

learning and practicing is two separate things... jeremy suggests you learn first then practice not vice versa...

you should be reading up PHP from a few tutorial sites then attempting to code because when you just practice you might get a full 20 page/script site working like you want... but most people don't use sites like you would expect therefore with a strong knowledge of the language you're able to cover all the loopholes and all the exception cases...
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
orionoreo is offline
Reply With Quote
View Public Profile
 
Old 07-16-2009, 06:33 PM Re: Email sent depends on drop down option selected - help ...
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Quote:
Originally Posted by orionoreo View Post
learning and practicing is two separate things... jeremy suggests you learn first then practice not vice versa...

you should be reading up PHP from a few tutorial sites then attempting to code because when you just practice you might get a full 20 page/script site working like you want... but most people don't use sites like you would expect therefore with a strong knowledge of the language you're able to cover all the loopholes and all the exception cases...
Well said.

@jennifer: As an enticement, consider that the first step academics will tell you to coding has nothing to do with sitting down in front of a computer.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to Email sent depends on drop down option selected - help ...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16528 seconds with 12 queries