Web Analytics Made Easy -
StatCounter A simple send mail script but why doesn't it work? - CodingForum

Announcement

Collapse
No announcement yet.

A simple send mail script but why doesn't it work?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • A simple send mail script but why doesn't it work?

    I've had this really simple script for quite some time and I do remember it worked in the past (5+ years ago) but it just doesn't work anymore...

    I have a web-page with a form where you input all the fields, then hit submit and it sends me an email with the input. It does send an email however it doesn't send any of the fields that were input in the form.

    Here's the script:

    PHP Code:
    <?php

    $mysubject 
    "New Message";
    $message "ID: $id
    Email: 
    $email
    name: 
    $name
    price: 
    $price
    link: 
    $link
    Subject: 
    $subject
    Body:
    $body
    ---end---"
    ;
    $url "success.htm";

    mail("John <[email protected]>"$mysubject$message"From: Jane <[email protected]>");

    header("Location: $url");
    ?>
    The form fields that are being input and that I need sent back to me are:

    Code:
    $id
    $email
    $name
    $price
    $link
    $subject
    $body

  • #2
    In your code, where are the lines of code that are setting the variables $id, $email, $name, $price, $link, $subject, and $body?

    Your code is dependent on register_globals to magically populate variables from form data. Unfortunately, register_globals also magically allowed hackers to set session variables and take over web sites. register_globals were the worst security hole that was ever deliberately added to a programming language. register_globals were turned off by default 7 years ago in php4.2 and they have been completely removed in php6.

    You must use $_POST variables in your code to access form data.
    Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.

    Comment


    • #3
      Can you advise as to how to do that? I'm not fluent in PHP I just need a quick way to create a form... security, etc. isn't that much of an issue as it'll be in a password-protected folder.

      Comment


      • #4
        I know that you can directly access the variable with the same name as form’s field name but it is not way or style of software development.

        I have added additional var_dump() to see that both variables has correct values. You will need to remove it and uncomment last line with redirect after debugging will be finished.

        PHP Code:
        <?php
        $id 
        = isset($_REQUEST['id']) ? $_REQUEST['id'] : 'id field is not set';
        $email = isset($_REQUEST['email']) ? $_REQUEST['email'] : 'email field is not set';
        $name = isset($_REQUEST['name']) ? $_REQUEST['name'] : 'name field is not set';
        $price = isset($_REQUEST['price']) ? $_REQUEST['price'] : 'price field is not set';
        $subject = isset($_REQUEST['subject']) ? $_REQUEST['subject'] : 'subject field is not set';
        $body = isset($_REQUEST['body']) ? $_REQUEST['body'] : 'body field is not set';

        $mysubject "New Message";
        $message "ID: $id
        Email: 
        $email
        name: 
        $name
        price: 
        $price
        link: 
        $link
        Subject: 
        $subject
        Body:
        $body
        ---end---"
        ;
        $url "success.htm";

        var_dump($mysubject$message); // REMOVE THAT

        mail("John <[email protected]>"$mysubject$message"From: Jane <[email protected]>");

        // UNCOMENT header("Location: $url");
        ?>

        Comment

        Working...
        X