PamD
PamD

Reputation: 11

Emailing data from a form to a selected recipient

I have a form that a person fills out. The data in the form is emailed to another person. It needs to be directed to the proper person. They select the person from a dropdown. I know how to send data to a person in an email but do I have to do an If statement for each person on the list or can it be done with a variable by substituting the variable in this command? Would this be the correct code that checks to see if the person choose "option 1" as the contact person?

This is the syntax I used to see if the person chose the first option but it doesn't send the email it to that person. If I remove this && ($_POST ["Police"]=1) it sends the email to the person but there are going to be several choices.

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") && ($_POST ["Police"]=1)){
  $insertSQL = sprintf("INSERT INTO help (snumber, who, what, `when`, `where`, why) VALUES (%s, %s, %s, %s, %s, %s)",
                   GetSQLValueString($_SESSION['MM_Username'], "text"),
                   GetSQLValueString($_POST['Who'], "text"),
                   GetSQLValueString($_POST['What'], "text"),
                   GetSQLValueString($_POST['When'], "text"),
                   GetSQLValueString($_POST['Where'], "text"),
                   GetSQLValueString($_POST['Why'], "text"));
  mail ("[email protected]", 
      "Submission from ".$_POST["user"], 
      $_POST["user"]." Has submitted the following information "."\n" .
      "Who :".$_POST["Who"]."\n".
      "What: ".$_POST["What"]."\n".
      "When: ".$_POST["When"]."\n".
      "Where: ".$_POST["Where"]."\n".
      "What and Why: ".$_POST["Why"]);
}   

Upvotes: 0

Views: 45

Answers (1)

Robbert
Robbert

Reputation: 6592

You have an error in your code:

$_POST ["Police"]=1 should be $_POST["Police"]==1

First, no space after $_POST, but even then the single = will cause the value of $_POST['Police'] to be assigned a value of 1 and always return true. Using the double = will just check if the value of $_POST['Police'] is equal to 1.

Upvotes: 1

Related Questions