1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

does anyone know how to make this work

Discussion in 'PHP' started by Top$hottEr, Mar 10, 2008.

  1. #1
    html

    <form method="post" action="sendmail.php">

    <fieldset>
    <legend>Personal Information</legend>>
    <label for="firstname" accesskey="f">First name: </label>
    <input type="text" id="firstname" name="firstname" value="" tabindex="1">
    <label for="lastname" accesskey="l">Last name: </label>
    <input type="text" id="lastname" name="lastname" tabindex="2">
    <label for="email" accesskey="e">Email: </label>
    <input type="text" id="email" name="email" tabindex="3">
    </fieldset>
    <fieldset>
    <legend>Comments</legend>
    <label for="comments" accesskey="c">Enquires: </label>
    <textarea id="comments" rows="8" cols="20" name="comments"></textarea>
    <input type="submit" value="Submit" tabindex="5"> <input type="Reset" tabindex="6">
    </fieldset>



    php
    <?php
    $firstname = $_REQUEST['firstname'] ;
    $lastname = $_REQUEST['lastname'] ;
    $email= $_REQUEST['email'] ;
    $comments= $_REQUEST['comments'] ;
    mail( "........@hotmail.co.uk", "Feedback Form Results",
    $message, "From: $email" );
    header( "Location: http://www.example.com/thankyou.html" );
    ?>
     
    Top$hottEr, Mar 10, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    And the problem is...?
     
    nico_swd, Mar 10, 2008 IP
    smatts9 likes this.
  3. Top$hottEr

    Top$hottEr Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    sorry i made a form with fieldsets and want the form to be e-mailed to my e-mail but what i tried does not work am new to this so bare with me
     
    Top$hottEr, Mar 10, 2008 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Try:
    
    
    <?php
    $firstname = $_REQUEST['firstname'] ;
    $lastname = $_REQUEST['lastname'] ;
    $email= $_REQUEST['email'] ;
    $comments= $_REQUEST['comments'] ;
    
    $message = htmlspecialchars("{$firstname}, {$lastname} ({$email})\n\n{$comments}");
    
    mail
    (
        "........@hotmail.co.uk",
        "Feedback Form Results",
        $message,
        "From: " . preg_replace('~[^\w-\.@\+]+~', null, $email)
    );
    
    header( "Location: http://www.example.com/thankyou.html" );
    
    ?>
    
    
    PHP:
     
    nico_swd, Mar 10, 2008 IP
  5. Top$hottEr

    Top$hottEr Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    tried that it doesnt work anything to do with the submit
     
    Top$hottEr, Mar 10, 2008 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Can you please use periods and commas? lol.. it's a bit hard to say where your sentences finish.

    Anyway, I don't know what you're saying about the submit, but you're missing a closing </form> tag at the end. Might be the issue? Does your form submit at all?

    Or don't you receive the email? Try using a non-hotmail address. Hotmail can be a pain in the ass sometimes.
     
    nico_swd, Mar 10, 2008 IP
  7. Top$hottEr

    Top$hottEr Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ok sorry, i have tried changing the address to a non hotmail and it still doesnt work, and i have a </form>.
    my form doesnt submit & i dont receive anything, do ihave to write any php in the index page
     
    Top$hottEr, Mar 10, 2008 IP
  8. VernonK

    VernonK Peon

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Is there a particular reason you're using $_REQUEST instead of $_POST?

    Also... not sure but you may want to try using a class such as PHPMailer. I would put the link, but unfortunately I haven't posted enough to add links to my posts yet.
     
    VernonK, Mar 10, 2008 IP
  9. Gonzo4u

    Gonzo4u Well-Known Member

    Messages:
    410
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #9
    I was wondering too why you are using $_REQUEST instead of $_POST when your form data is POST.

    If you use $_REQUEST you have no guarantee that the data came from the post data, which leads to security holes in your script. You might want to use $_REQUEST if you've got some variables on a form that can come in either via $_POST or $_GET.

    Try using $_POST and it will solve your problem.

    For mailing solutions PHPMailer is a good choice, you can try with that.


    Regards,
    Gonzo
     
    Gonzo4u, Mar 10, 2008 IP
  10. VernonK

    VernonK Peon

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Glad to see I wasn't the only one wondering about this. ;)
     
    VernonK, Mar 10, 2008 IP
  11. lephron

    lephron Active Member

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #11
    There is nothing wrong with using $_REQUEST instead ofo $_GET/$_POST - in fact I'd say it is better to use $_REQUEST as it makes it easier to change from post/get requests, and makes debugging much easier.

    Using $_REQUEST instead of $_GET/$_POST poses no security risk at all - all your input should be checked and validated no matter where it comes from.
     
    lephron, Mar 10, 2008 IP
  12. VernonK

    VernonK Peon

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    That's the thing, we're talking reality here. We all know that with the ease of learning PHP in the beginning, that there are MANY web forms using PHP that do not validate their form data. Just a thought, I could be way off base though. What do you think?
     
    VernonK, Mar 10, 2008 IP
  13. lephron

    lephron Active Member

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #13
    If you think using $_POST instead of $_REQUEST gives you added security then I'd be really worried about your scripts! Just because you KNOW data is being posted doesn't make it any more secure, and not much more difficult to send malicious data.
     
    lephron, Mar 11, 2008 IP
  14. Gonzo4u

    Gonzo4u Well-Known Member

    Messages:
    410
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #14
    First of all $_REQUEST is less strict than $_POST or $_GET and you can't ensure where your imputs are coming from and in that context it is less secure.

    Suppose if you are relying on your POST data to be submited, then anybody can simply override it by passing a GET string eg: www.websitename.com?var=somevalue.

    Again using $_REQUEST posses more risk of SQL injection vulnerability if your script is not properly coded.

    If you are using cookies for tracking or authorization then this problem may arise if you are ignorant. As cookies are also put into $_REQUEST at last. Any data sent by $_POST or $_GET will be overwritten by cookie with same names.

    eg:
    $_POST[”username”] = “post value”; eg. Hari
    $_GET[”username”] = “get value”; eg. Tom
    $_COOKIE[”username”] = “cookie value"; eg. Jack

    Now
    $_REQUEST[”username”] = “Jack”;

    Here $_REQUEST is overwritten by cookie value even thou your $_POST or $_GET values are different, but all have a common variable name i.e username.

    I am not saying using $_REQUEST is security risk but it leads to security vulnerability with poor coding.

    Regards,
    Gonzo
     
    Gonzo4u, Mar 11, 2008 IP
  15. Gonzo4u

    Gonzo4u Well-Known Member

    Messages:
    410
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #15
    No way your script will be secured even by using $_POST or $_GET instead of $_REQUEST. The only advantage is they are more strict compared to $_REQUEST which is less strict, as you know where your inputs are coming from. What makes the script more secure is the coding and handling of it.

    Regards,
    Gonzo
     
    Gonzo4u, Mar 11, 2008 IP
  16. Top$hottEr

    Top$hottEr Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    ok i understand you can use both and each has security issues, but can anyone tell me why my code doesnt work, or if its correct
     
    Top$hottEr, Mar 13, 2008 IP
  17. lephron

    lephron Active Member

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #17
    Have you tried nico's solution
     
    lephron, Mar 13, 2008 IP
  18. Top$hottEr

    Top$hottEr Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    yes i have and it still doesnt work
     
    Top$hottEr, Mar 16, 2008 IP
  19. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #19
    It's been nearly a week now, and it's about time we fix this.

    Let's see if your host allows the mail() function at all. What output does this give you?
    
    <?php
    $firstname = $_REQUEST['firstname'] ;
    $lastname = $_REQUEST['lastname'] ;
    $email= $_REQUEST['email'] ;
    $comments= $_REQUEST['comments'] ;
    
    $message = htmlspecialchars("{$firstname}, {$lastname} ({$email})\n\n{$comments}");
    
    echo mail
    (
        "........@hotmail.co.uk",
        "Feedback Form Results",
        $message,
        "From: " . preg_replace('~[^\w-\.@\+]+~', null, $email)
    )
        ? 'Mail sent'
        : 'Error sending mail';
    
    ?>
    
    PHP:
     
    nico_swd, Mar 16, 2008 IP
  20. Top$hottEr

    Top$hottEr Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #20
    this gives me a blank page thats says mail sent, but no e-mail is sent to my e-mail destination
     
    Top$hottEr, Mar 17, 2008 IP