25 users online (1 members and 24 guests)  


  Results 1 to 6 of 6

Related

  1. PHP formmail problem    Forum: PHP Forum
    Replies: 3
  2. FormMail.pl    Forum: CGI Perl Forum
    Replies: 4
  3. FormMail Help    Forum: CGI Perl Forum
    Replies: 15
  4. Formmail help    Forum: CGI Perl Forum
    Replies: 1
  1. #1
    MarkR's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2005
    Posts
    3

    Conditions for formmail

    Hi there,

    I apologise in advance in my lack of knowledge but I have a problem im stuck with.

    Im currently working on a college project in php whereby dependent on the value entered in a html form the contents are emailed to the relevent recipient. So for example if the value was greater than 5000 it would be emailed to x and if less than would by emailed to recipient y.

    Currently I can only get the form going to both parties. Is this possible using php? Im not converse with php scripting and only have knowledge of using the formmail script provided by my hosting company.

    Any help would be greatly appreciated.

    Many thanks

    Mark

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Hiya, welcome to the forums.

    Your going to have to throw the generic formailer out the window, and code something yourself.

    PHP is very capable of deciding who to send to based on any data at all.


    Code:
    <?php
    if ($variable > 5000) {
    $mailto = "bob";
    } else {
    $mailto "jim";
    }
    ?>
    However, there is more to it than that. Start with PHP's Mail Manual Page on how to send the actual email itself. Using that and IF Statements you should be able to achieve what you need.

    Feel free to post back if you need more help, and no need to apologise for a lack of knowledge, thats how we all got here
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    MarkR's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2005
    Posts
    3
    Many thanks for your repsonse!

    I had a look over the mail function and got something to work which I was really happy with.

    I was worried of the security implications of coding a script like that myself from scratch.

    Would you not suggest altering the formmail script directly to include an IF statement?

    Im currently using the PHORM form to email processor.

    Thanks again for your help.

    Regards

    Mark

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    PHORMS's actually pretty good. It's definitely not going to hurt to amend that instead of writing your own. However, its never too early to learn about security and writing one yourself is going to teach you that. Mail forms are a pretty good way to learn, as they teach you to validate user entry (EVERYTHING that a user can enter should be validated to death) without the risk of SQL Injection (A popular form of attack, using inputs).

    Obviously, its up to you. Chances are, if you amend PHORM without a good knowledge of security, its quite possible you will make it insecure anyway. I would suggest bone up on the simpler aspects of good PHP coding practices and write your own.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  5. #5
    MarkR's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2005
    Posts
    3
    Thanks for your advice on creating my own script, its something I would like to do however as I mentioned previously this is a college project and Im on a strict deadline!

    I have ammended the PHORM script to allow for the if statement to occur as shown below.

    Code:
    if( $_POST["amount"] >= 5000 )
    {
      $PHORM_TO[1] = "me@mydomain.com";
    }
    else
    {
      $PHORM_TO[1] = "me@anotherdomain.com";
    }
    Im using currencies, and if a user submits it as 5000 it doesnt go to the same email address if I was to type 5000 which some users may do. How might I prevent this from happening?? I was looking at a drop down list but would prefer if users could enter (5000, 5000, 5000.00 or 5000.00) for example as users could enter 5234.54...

    Thanks again

    Mark

  6. #6
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    You could check with is_numeric to make sure its a purely numeric value.

    Alsom, following the link above, there are some functions to convert the value to a number, so if someone type 2,500 it will automatically become 2500. Hope that help.s
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?



Tags for this Thread