Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Form to email help

    I am not a php person and need some help, please.

    I have the following rudementary form to email code.
    (I did not write this code.)
    It is in a file named mail.php on the server.

    PHP Code:
    <?PHP 

    $to 
    "me@this.com";

    $subject "Results from your Request Info form"

    $headers "From: My Site"

    // redirect? 1=yes 0=no
    $forward 0
    $location "mysite.com"

    $date date ("l, F jS, Y"); 
    $time date ("h:i A"); 

    $msg "Below is the result of your feedback form. It was submitted on $date at time.\n\n"

    if (
    $_SERVER['REQUEST_METHOD'] == "POST") {
        foreach (
    $_POST as $key => $value) { 
            
    $msg .= ucfirst ($key) ." : "$value "\n"
        }
    }
    else {
        foreach (
    $_GET as $key => $value) { 
            
    $msg .= ucfirst ($key) ." : "$value "\n"
        }
    }

    mail($to$subject$msg$headers); 
    if (
    $forward == 1) { 
        
    header ("Location:$location"); 

    else { 
        echo 
    "Thank you for submitting our form. We will get back to you as soon as possible."


    ?>

    The following is a typical response:

    Below is the result of your feedback form.
    It was submitted on Friday, February 1st, 2013 at 03:30 PM.

    name : test
    Phone : asdf
    Email : sdfg@sdfg.com
    Submit : Submit Request


    THe code works fine when called from the web page with the form except every now and then I get an email without the fields such as this:

    Below is the result of your feedback form.
    It was submitted on Friday, February 1st, 2013 at 05:30 PM.


    I discovered that if you access the mail.php file directly by typing

    http://mysite.com/mail.php

    in your browser you get an email without the fields.


    Is there a better way of doing this?

    Any comments would be helpful. Thanks.

  • #2
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • Users who have thanked student101 for this post:

    jack0987 (02-02-2013)

  • #3
    New Coder
    Join Date
    Sep 2011
    Posts
    35
    Thanks
    18
    Thanked 1 Time in 1 Post
    if all you want is to prevent users from accessing the mail.php themselves then just add
    PHP Code:
    if(isset($_POST)) {

    //your content

    }

    else {

    echo 
    "Forbidden";
    //or
    header('Location: index.php'); //which will bring them back to home page



  • Users who have thanked elem for this post:

    jack0987 (02-02-2013)

  • #4
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks so much for the replies.

    Actually elem I did do something very similar to that yesterday.

    I have a suspicion that it is being done intentionally. For what it's worth, perhaps I could catch the http line or ip address but I do not know how to do that.

  • #5
    New Coder
    Join Date
    Sep 2011
    Posts
    35
    Thanks
    18
    Thanked 1 Time in 1 Post
    Do you mean that someone is intentionally pressing send without filling out any fields? Then you could write a few lines that would check if all the fields are filled out, if not form wouldn't be sent. Or install captcha or some other anti-spam script, if you suspect it is not a human ...

  • #6
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts
    No, I think someone may be running the mail.php directly. As far as I can tell it is the only way the email would be totally blank - have no field names at all. If they were hitting submit the field names would be present but empty.

  • #7
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by jack0987 View Post
    No, I think someone may be running the mail.php directly. As far as I can tell it is the only way the email would be totally blank - have no field names at all. If they were hitting submit the field names would be present but empty.
    Edit: reference

    You still getting blank emails after applying the above?
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #8
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts
    No. The above application corrects it. Thanks.

    I think I may still like to catch the IP and http line that runs it perhaps.
    Last edited by jack0987; 02-03-2013 at 03:59 PM.


  •  

    Posting Permissions

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