Page 1 of 4 123 ... LastLast
Results 1 to 10 of 36

Thread: Form email notification depends on drop down

  1. #1
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Form email notification depends on drop down

    Is it posible to have a email sent to differant people depending on a selection made from a drop down on a form. The drop down choices are Wichita, AMain, Hutchison, Enid, Action, Newton. Only one can be selected on the form. So for instance if Wichita was selected an email would be sent to wichita@wichita.com If AMain was selected an email would go to AMain@amain.com and so on.
    Here is the PHP
    PHP Code:
    <?php
    include("global.inc.php");
    $errors=0;
    $error="The following errors occured while processing your form input.<ul>";
    pt_register('POST','FirstName');
    pt_register('POST','LastName');
    pt_register('POST','Address');
    pt_register('POST','City');
    pt_register('POST','State');
    pt_register('POST','ZipCode');
    pt_register('POST','HomePhone');
    pt_register('POST','CellPhone');
    pt_register('POST','EMail');
    pt_register('POST','MembershipNo');
    pt_register('POST','RoarNo');
    pt_register('POST','FirstClass');
    pt_register('POST','TransmitterFrequency');
    pt_register('POST','TransponderNo');
    pt_register('POST','TrackTransponder');
    pt_register('POST','SecondClass');
    pt_register('POST','TransmitterFrequency2');
    pt_register('POST','TransponderNo2');
    pt_register('POST','TrackTransponder2');
    pt_register('POST','AbilitySkillLevel');
    pt_register('POST','RaceDate');
    pt_register('POST','Track');
    pt_register('POST','IPAddress');
    pt_register('POST','DatePosted');
    if(
    $FirstName=="" || $LastName=="" || $Address=="" || $City=="" || $State=="" || $ZipCode=="" || $EMail=="" || $FirstClass=="" || $TransmitterFrequency=="" || $AbilitySkillLevel=="" || $RaceDate=="" || $Track=="" ){
    $errors=1;
    $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
    }
    if(!
    eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$EMail)){
    $error.="<li>Invalid email address entered";
    $errors=1;
    }
    $IPAddress $HTTP_SERVER_VARS["REMOTE_ADDR"];
    $DatePosted date("Y-m-d h:i");
    if(
    $errors==1) echo $error;
    else{
    $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
    $message="First Name: ".$FirstName."
    Last Name: "
    .$LastName."
    Address: "
    .$Address."
    City: "
    .$City."
    State: "
    .$State."
    Zip Code: "
    .$ZipCode."
    Home Phone: "
    .$HomePhone."
    Cell Phone: "
    .$CellPhone."
    E Mail: "
    .$EMail."
    Membership No: "
    .$MembershipNo."
    Roar No: "
    .$RoarNo."
    First Class: "
    .$FirstClass."
    Transmitter Frequency: "
    .$TransmitterFrequency."
    Transponder No: "
    .$TransponderNo."
    Track Transponder: "
    .$TrackTransponder."
    Second Class: "
    .$SecondClass."
    Transmitter Frequency2: "
    .$TransmitterFrequency2."
    Transponder No2: "
    .$TransponderNo2."
    Track Transponder2: "
    .$TrackTransponder2."
    Ability Skill Level: "
    .$AbilitySkillLevel."
    Race Date: "
    .$RaceDate."
    Track: "
    .$Track."
    IP Address: "
    .$IPAddress."
    Date Posted: "
    .$DatePosted."
    "
    ;
    $message stripslashes($message);
    mail("wichita@wichita.com","".$FirstName." ".$RaceDate." Race Registration",
    $message,"From: $EMail");
    $link mysql_connect("localhost","logmein","withthispw");
    mysql_select_db("form_21D",$link);
    $query="insert into Registration (First_Name,Last_Name,Address,City,State,Zip_Code,Home_Phone,Cell_Phone,E_Mail,Membership_No,Roar_No,First_Class,Transmitter_Frequency,Transponder_No,Track_Transponder,Second_Class,Transmitter_Frequency2,Transponder_No2,Track_Transponder2,Ability_Skill_Level,Race_Date,Track,IP_Address,Date_Posted) values ('".$FirstName."','".$LastName."','".$Address."','".$City."','".$State."','".$ZipCode."','".$HomePhone."','".$CellPhone."','".$EMail."','".$MembershipNo."','".$RoarNo."','".$FirstClass."','".$TransmitterFrequency."','".$TransponderNo."','".$TrackTransponder."','".$SecondClass."','".$TransmitterFrequency2."','".$TransponderNo2."','".$TrackTransponder2."','".$AbilitySkillLevel."','".$RaceDate."','".$Track."','".$IPAddress."','".$DatePosted."')";
    mysql_query($query);
    ?>

  2. #2
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Just do an if, else if, else if, else if, else if, else if statement. Make a variable called $to or something and give it a different value depending on the if/if else statement, then call it in the mail function: mail($to...
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  3. #3
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    yes

    you put the value of the select dropdown menu as the to in the mail function

    Code:
    <form action="process.php" method="post">
    <select name="email-to">
      <option value="whichita@blah.com">Whichita</option>
      <option value="AMain@blah.com">AMain</option>
    </select>
    process.php
    PHP Code:
    $to $_POST['email-to'];
    $subject "_SUBJECT_OF_EMAIL_";

    // build your message here
    $message " ";

    mail($to$subject$message); 

  4. #4
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Ha, I should have thought of that. That option is easier, but it can be easily hijacked by someone. They can use a simple firefox extension to "edit the html" and submit it to whatever email address they'd like.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  5. #5
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by alexjewell View Post
    Ha, I should have thought of that. That option is easier, but it can be easily hijacked by someone. They can use a simple firefox extension to "edit the html" and submit it to whatever email address they'd like.
    i was showing him the method... you should always sanitize the data... and ideally what he should do is probably something like
    Code:
    <select name="email-to">
       <option value="whichita">Whichita</option>
       <option value="AMain">AMain</option>
    ...
    </select>
    process.php
    PHP Code:
    $checkArray = array(
      
    'wichita' => 'email address',
      
    'amain' => 'email address',
    ...
    );

    $email trim(strip_tags(strtolower($_POST['email-to'])));\
    $to $checkArray[$email];

    mail($to$subject$message); 
    the $checkArray is an array of all of the possible answers. the initial value of the email is trimmed for whitespace, strips all tags that a malicious user might have tried to code in, and it lowers the string to make sure its in the correct format.
    $to = gets the value from the $checkArray according to the name which is the key.

    then you proceed with the mailing

  6. #6
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry but as Iam a newbie and stuff Im not fallowing this. Do I put this "email-to" in the form like this
    <select name="email-to"'Track' style="font-weight: bold; font-style:italic">
    <option value='Wichita' selected>Wichita
    <option value='A Main'>A Main
    </select>

    Then where in the process.php do I put
    PHP Code:
    $checkArray = array(
      
    'wichita' => 'email address',
      
    'amain' => 'email address',
    ...
    );

    $email trim(strip_tags(strtolower($_POST['email-to'])));
    $to $checkArray[$email];

    mail($to$subject$message); 
    Then what do you mean you should always sanitize the data

  7. #7
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by big-dog1965 View Post
    Sorry but as Iam a newbie and stuff Im not fallowing this.
    thats okay Sorry I wasnt clear enough.

    Quote Originally Posted by big-dog1965 View Post
    Code:
    Do I put this "email-to" in the form like this
    <select name="email-to"'Track' style="font-weight: bold; font-style:italic">
    <option value='Wichita' selected>Wichita
    <option value='A Main'>A Main
    </select>
    yes that is correct you put the "name" of the select drop down as email-to / whatever you want to name it. it doesn't have to be that, but you need to be sure to know what it is for the next step.]

    Quote Originally Posted by big-dog1965 View Post
    Then where in the process.php do I put
    PHP Code:
    $checkArray = array(
      
    'wichita' => 'email address',
      
    'amain' => 'email address',
    ...
    );

    $email trim(strip_tags(strtolower($_POST['email-to'])));
    $to $checkArray[$email];

    mail($to$subject$message); 
    this is a segment of the php yes.. but in order for this part to work you need to work of what I did initially also.. below is the script that combines both. the second portion of this script is where you are assigning the email to its corresponding address. I only created 2 of them to show you how its done, and I am sure you can copy my example.
    1) make sure the <option value="A Main"> and the key in the array("A Main" remain the exact same, otherwise the email address will not be picked up and you wont be able to send the email.
    2) trim() deletes the leading and trailing spaces
    strip_tags() will delete any harmful php tags
    strtolower() will take whatever is in the email-to value and make it entirely undercase. I did this so it was 1 less thing you needed to worry about, but is not needed as long as you make sure that the form and the array values are the same.


    PHP Code:
    $email trim(strip_tags(strtolower($_POST['email-to'])));
    $checkArray = array(
      
    'wichita' => 'email address',
      
    'amain' => 'email address',
    ...
    );
    $to $checkArray[$email];

    $subject "_SUBJECT_OF_EMAIL_";

    // build your message here 
    // this is what will show up in the body of the email
    $message " ";

    if( !
    mail($to$subject$message) )
    {
       echo 
    "<h1>Unable to send email, Please try again later</h1>";
    }
    else 
    {
       echo 
    "<h1>Email Sent. Thank You</h1>";

    if all you want to do is send an email to someone then you can just use this as your entire process.php script, with a few adjustments to fit your specific needs.

    1) email-to
    you do not have to have this the same as what you have in your <form> however whatever you use you must be sure to change it through all of the corresponding instances as well.

    2) subject
    I left it up to you to decide what you want the "subject" of the email to be. if you want the user to decide the subject then that would require a little bit of extra coding and again you would need to make sure that the "name" attribute of the form match the processing.

    3) the message
    I didn't put anything in here, because I didn't know how you were going to handle it. if you need a script to help you populate the message body of the email then please letme know and I will write something up...

    4) actual mailing
    I took the liberty of creating the actual mail portion of the script for you.. The script will attempt to send the email, and if it can send the email, it will display the thanks heading, and if there is an error it will display the error heading. there is alot of flexibility in that, you would just need to change the "echo", which would print out the heading, to whatever you wish it to say.. or you can delete it altogether and decide what you want to do with it from there, be it a redirect etcetc...


    Quote Originally Posted by big-dog1965 View Post
    Then what do you mean you should always sanitize the data
    You should sanitize everything that comes from the user (client-side) because there are certain tags / scripts that when ran can create a problem in not only php, but every language. Now whether the user just mistakenly entered in something in correctly or it was a user being intentionally malicious, you do not want to give them access to your system beyond what you say is okay. It is possible for someone to create their own form and use that to submit to your script, and if that script has malicious code, it can be destructive.

    if you have any questions on that please let me know... and I will try to answer them as thoroughly and quickly as possible.

  8. #8
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Can I just use this much of your code to make it work and where would I paist it in at in that code
    PHP Code:
    $email trim(strip_tags(strtolower($_POST['Track']))); 
    $checkArray = array( 
      
    'wichita' => 'email address'
      
    'amain' => 'email address'
    ... 
    ); 
    $to $checkArray[$email]; 
    Because if you notice the php code I suplied takes the user to a thank you page of sorts and the code also has all the info that gets sent to the email by pulling it from the Database (I think thats where it comes frome anyway)

    If it makes it easier to see what Im doing wichitarcraceway
    On left youll see registration if you click that you can fill out stuff and submit then youll see results the same results are sent to email
    Last edited by big-dog1965; 09-03-2007 at 11:24 PM.

  9. #9
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    I didnt look at the code you sent initially, however now I am confused. The code you sent me is collecting data from the form then it is doing 2 things. It is populating and sending the email and it is also connecting to the database and attempting to insert data into there. now ifyou are attempting to do both, my script needs some adjustments. If you are indeed attempting to "register" a new user, you should try to register them before sending the email.. and then if the registration goes correctly you should email the user of the changes....

    Also I am unfamiliar with the
    PHP Code:
    pt_register() 
    function, and it is not listed on php.net. It looks as if it is obtaining and declaring a variable at the same time, which would be a good thing if thats what its doing.. if thats not what it is doing, then I am afraid to say that all of that is useless as you haven't declared any of those variables.

    I am going to take it that the "Track" is the name of the email select input? if that is then yes you can just copy and paste that info into the script you have.

    When I first look at the "subject" portion of the email script I got very very very confused, but if you will be the only one who EVER looks at this script and you remember than I guess it would be okay... I would have broken that out and created the "subject" variable... and put all of that content as the contents, this way it makes for easier debugging in the future, but its your choice.

    the last thing I would say is kinda redundant, you are attempting to send the email first before you input the data into the database... I would input the data into the database, and if that is successful, then send the email, otherwise you could get extra emails if there was an error in inserting the data into the database, that you wouldn't get if you waited until the success of the insertion.

    Just some constructive criticism

    I hope that cleared that all up...

  10. #10
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I used a formgenarater to creat the form it created everything including the DB. It seems to work ok I get an email and everything. Really the only on going problem I have is the date if the user enters it DDMMYYYY insted of YYYYMMDD the DB doesnt store the information but I still get the email so I know someone register. I added the Track field because some people go to other tracks so insted of me having to sort the information for each track the other track can take care of there own stuff. the current register on the web doesnt have the new form with the track field because it is in use and until I can get the track field worked out didnt want it live, but it functions the same just without the track field and emails to indivigual tracks

    Did I loose my help on this?
    I tried to paist the code you made in several differant places and got errors not knowing coding I delete or change what I thought was errors, but still errors
    Please Help
    The form is so people know where others are racing. really informational only, but helps track directors see whos coming to race as well by email
    Last edited by big-dog1965; 09-04-2007 at 07:23 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •