Results 1 to 4 of 4

Thread: Prevention of Double Send

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Posts
    9

    Unhappy Prevention of Double Send

    I just wrote a simple E-mail form that I have on my homepage but I found 1 slight bug and I dont know how to fix it. What happends is after you submit an E-mail It shows E-mail sent or whatever but if you refresh the page it sends the e-mail again. Here is the code:
    <?
    if (isset($_REQUEST['page'])) {
    $id = $_REQUEST['page']; }
    if($page == sent) {
    $message = "$mess

    Ip: $REMOTE_ADDR";
    $toaddy = "[email protected]";
    $test = "E-mail";
    $testt = "Comment";
    //I made the Comment Was Sent! so spammers won't know that if they click send without changing whats in the text boxes that it wont send so that way they will waste there time clicking that and not waste my time with spam...
    if($message == $testt){echo "Comment Was Sent!";}
    elseif($fromaddy == $test){echo "Comment Was Sent!";}
    elseif($mess == $testt){echo "Comment Was Sent!";}
    elseif($fromaddy == NULL){echo "Comment Was Sent!";}
    elseif($mess == NULL){echo "Comment Was Sent!";}
    else {mail($toaddy, "Comment!", $message, "From:$fromaddy");
    echo "Comment was Sent!";}}

    else {
    echo "<form action=\"$phpself?page=sent\" method=\"post\">
    <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
    <td> <input type=\"text\" name=\"fromaddy\" value=\"E-mail\" size=\"14\"></td>
    </tr>
    <tr>
    <td> <textarea name=\"mess\" rows=3 cols=10>Comment</textarea></td>
    </tr>
    <tr>
    <td>
    <input type=\"submit\" value=\"Submit\"></form></td>
    </tr>
    </table>";}
    ?>
    Thanks!
    Tom-E - www.skateboard-city.com

  2. #2
    New Member
    Join Date
    Jan 2003
    Posts
    11
    THe best way around this (IMO) is to save a list of IPs of people who sent mail, and the time they sent it last (best done in a DB). That way you can check if that same person has already sent an email recently (say within 30 seconds) and alter your code so it doesn't send the mail if it's that soon.

    HTH

  3. #3
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    no the best way is to go to another page so if you hit refresh it does send it again. actually that is the only way.

    so after they hit send it loads another page then that page sends the mail then forwards to a thank you page or something.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Posts
    9
    hmm, i really dont want to involve a database with such a simple script.
    Thanks for the input I got some ideas now I think i can figure something out...
    Thanks!
    Tom-E
    Tom-E - www.skateboard-city.com

Posting Permissions

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



Click Here to Expand Forum to Full Width