new to php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Desmond

    #1

    new to php

    This is my first attempt ever at php can anyone glance over this
    code segmant and tell me were I am going wrong please

    ---- HTML ----
    <html>
    <head>
    <title>Email Me</title>
    <body>
    <p>
    </head>
    <table width="400">
    <tr>
    <td>
    <form action="email.p hp" method="POST">
    Subject:
    <br>
    <input type="text" name="subject" size="20" maxlength="30">
    <p>
    Message:
    <br>
    <textarea rows="8" name="message" cols="25"></textarea>

    <p>
    <input type="submit" value="Send">
    </form>
    </td>
    </tr>
    </table>
    </body>
    </html>

    ------------------------------
    ----PHP -------
    <html>
    <body>

    <?php
    $to = "otuatail@aol.c om";
    $from = "desotuatail@ao l.com";
    // $subject = "This is a test email";
    // $message = "Dear Desmond,\n\n\n This is just a test email.\n\n[color=blue]
    >From Chris.";[/color]

    // $headers = "From: $from\r\n";

    $success = mail($to, $HTTP_POST_VARS["subject"],
    $HTTP_POST_VARS["message"]);
    if ($success)
    echo "The email to $to from $from was successfully sent";
    else
    echo "An error occurred when sending the email to $to from
    $from";
    ?>

    </body>
    </html>

  • Andrew DeFaria

    #2
    Re: new to php

    Desmond wrote:
    [color=blue]
    > This is my first attempt ever at php can anyone glance over this code
    > segmant and tell me were I am going wrong please[/color]

    As I often like to ask when people ask such not well thought out
    questions: What was your first indication that it failed? Also, what
    have you done in your attempts to debug it?
    [color=blue]
    > ---- HTML ----
    > <html>
    > <head>
    > <title>Email Me</title>
    > <body>
    > <p>
    > </head>
    > <table width="400">
    > <tr>
    > <td>
    > <form action="email.p hp" method="POST">
    > Subject:
    > <br>
    > <input type="text" name="subject" size="20" maxlength="30">
    > <p>
    > Message:
    > <br>
    > <textarea rows="8" name="message" cols="25"></textarea>
    >
    > <p>
    > <input type="submit" value="Send">
    > </form>
    > </td>
    > </tr>
    > </table>
    > </body>
    > </html>
    >
    > ------------------------------
    > ----PHP -------
    > <html>
    > <body>
    >
    > <?php
    > $to = "otuatail@aol.c om";
    > $from = "desotuatail@ao l.com";
    > // $subject = "This is a test email";
    > // $message = "Dear Desmond,\n\n\n This is just a test email.\n\n[color=green]
    > >From Chris.";[/color]
    >
    > // $headers = "From: $from\r\n";
    >
    > $success = mail($to, $HTTP_POST_VARS["subject"],
    > $HTTP_POST_VARS["message"]);
    > if ($success)
    > echo "The email to $to from $from was successfully sent";
    > else
    > echo "An error occurred when sending the email to $to from
    > $from";
    > ?>
    >
    > </body>
    > </html>
    >
    > --
    > Headline: Bear takes over Disneyland in Pooh D'Etat![/color]

    Comment

    • Alvaro G Vicario

      #3
      Re: new to php

      *** Desmond wrote/escribió (15 Jun 2005 07:43:33 -0700):[color=blue]
      > This is my first attempt ever at php can anyone glance over this
      > code segmant and tell me were I am going wrong please[/color]

      Your main mistake is that you've tagged your usenet message to be ignored.
      Subject line should be used to provide a short description of what your
      message is about; that way, when there's traffic in the group, it can call
      the attention of someone who may have the knowledge to help. Also, you
      cannot just paste 50 lines of code and let others figure out what your
      problem is. Explain what your want to do and how your code fails to do so.
      Error messages are especially helpful.

      [color=blue]
      > <body>
      > <p>
      > </head>[/color]

      To begin with, this is not valid HTML. Check http://validator.w3.org/
      [color=blue]
      > <form action="email.p hp" method="POST">
      > $success = mail($to, $HTTP_POST_VARS["subject"],
      > $HTTP_POST_VARS["message"]);[/color]

      $HTTP_POST_VARS is deprecated, use $_POST instead.


      --
      -- Álvaro G. Vicario - Burgos, Spain
      -- http://bits.demogracia.com - Mi sitio sobre programación web
      -- Don't e-mail me your questions, post them to the group
      --

      Comment

      • Justin Koivisto

        #4
        Re: new to php

        Alvaro G Vicario wrote:
        [color=blue][color=green]
        >><form action="email.p hp" method="POST">
        >> $success = mail($to, $HTTP_POST_VARS["subject"],
        >>$HTTP_POST_VA RS["message"]);[/color]
        >
        > $HTTP_POST_VARS is deprecated, use $_POST instead.[/color]

        And filter the subject & message input so there isn't anything nasty in
        it before using the submitted info. (In this case, you may want to do
        something like strip_tags() on it since it's not an HTML MIME message.)

        Best to get in the practice of validating/filtering input and output
        from the beginning - event if it isn't necessary. It will save you a lot
        of headaches down the road...

        --
        Justin Koivisto - justin@koivi.co m

        Comment

        • Desmond

          #5
          Re: new to php

          I have downloaded a tutorial learn php in 6 days. But there is an area
          i don't understand. I am
          told to use

          <form action = "action1.ph p3" method = "POST">

          but how do i asign a php variable to it so I can use the following

          $success = mail($to, $subjec, $message);

          Please Desmond.

          Comment

          • Philip  Olson

            #6
            Re: new to php

            Read this:



            Comment

            • Desmond

              #7
              Re: new to php

              The indication that it failed was there was no email sent even though
              it said so. All I want to do is retreave the variables from the html
              page and send an email.

              this is it. I am new to php but ok on html



              Comment

              • Andrew DeFaria

                #8
                Re: new to php

                Desmond wrote:
                [color=blue]
                > The indication that it failed was there was no email sent even though
                > it said so.[/color]

                There that wasn't that hard was it. In the future always include what
                actually happened, error message, etc. - otherwise we are just guessing.

                Now did you think to stop and check to make sure what you put in was
                correct? By that I mean you used certain variables but were you sure
                that they contained what you thought they should contain? Adding display
                like debugging statements is always helpful.
                [color=blue]
                > All I want to do is retreave the variables from the html page and send
                > an email.[/color]

                Yes. Break the problem down and work on a small subset of the problem.
                Validate your assumptions before proceeding further. Another poster
                already hinted to the probable problem. IOW verify that you are doing
                "A" properly first before attempting "B". "A" here = "retrieve the
                variables from the html page". Are you sure you've retrieved them properly?

                Instead of plodding onward to emailing them how about simply displaying
                them to make sure they are correct first. Your email.php can instead of
                emailing simply write out HTML displaying the contents of what is passed
                in. Once you're sure that's correct then go onward.

                So instead of:

                <html>
                <body>

                <?php
                $to = "otuatail@aol.c om";
                $from = "desotuatail@ao l.com";
                // $subject = "This is a test email";
                // $message = "Dear Desmond,\n\n\n This is just a test email.\n\n[color=blue]
                >From Chris.";[/color]

                // $headers = "From: $from\r\n";

                $success = mail($to, $HTTP_POST_VARS["subject"],
                $HTTP_POST_VARS["message"]);
                if ($success)
                echo "The email to $to from $from was successfully sent";
                else
                echo "An error occurred when sending the email to $to from $from";
                ?>

                </body>
                </html>

                Try:

                <html>
                <body>

                <?php
                $to = "otuatail@aol.c om";
                $from = "desotuatail@ao l.com";

                $subject = $_POST["subject"];
                $message = $_POST["message"];

                print "subject = '$subject'<br>" ;
                print "message = '$message'<br>" ;

                if (mail($to, $subject], $message)) {
                echo "The email to $to from $from was successfully sent";
                } else {
                echo "Unable to send message";
                }
                ?>

                </body>
                </html>

                Additionally read up on the documentation about the function you are
                using - mail - http://us3.php.net/manual/en/function.mail.php. Also
                refer to http://us3.php.net/manual/en/ref.mail.php, especially the user
                comments about specifying a proper From address.
                [color=blue]
                > this is it. I am new to php but ok on html[/color]

                I'd say your html could use a little work too! ;-)
                [color=blue]
                > http://www.des-otoole.co.uk/email.html[/color]

                --
                [color=blue]
                > Too many freaks, not enough circuses.[/color]


                Comment

                • Desmond

                  #9
                  Re: new to php

                  Can someone please tel me the equivelent in PHP of this vbscript

                  Response.Redire ct "acknowledge".h tml Thanks

                  Comment

                  • Alvaro G Vicario

                    #10
                    Re: new to php

                    *** Desmond wrote/escribió (16 Jun 2005 02:58:54 -0700):[color=blue]
                    > Can someone please tel me the equivelent in PHP of this vbscript
                    >
                    > Response.Redire ct "acknowledge".h tml Thanks[/color]

                    header('Locatio n: http://' . $_SERVER['HTTP_HOST] . '/acknowledge".ht ml');
                    exit;


                    Although it does work with a relative location, I believe HTTP v1.1
                    requires a full URL.

                    --
                    -- Álvaro G. Vicario - Burgos, Spain
                    -- http://bits.demogracia.com - Mi sitio sobre programación web
                    -- Don't e-mail me your questions, post them to the group
                    --

                    Comment

                    • Nisse Engström

                      #11
                      Re: new to php

                      On Wed, 15 Jun 2005 15:11:25 GMT,
                      Justin Koivisto<justin @koivi.com> wrote:[color=blue]
                      > Alvaro G Vicario wrote:
                      >[color=green][color=darkred]
                      > >><form action="email.p hp" method="POST">
                      > >> $success = mail($to, $HTTP_POST_VARS["subject"],
                      > >>$HTTP_POST_VA RS["message"]);[/color]
                      > >
                      > > $HTTP_POST_VARS is deprecated, use $_POST instead.[/color]
                      >
                      > And filter the subject & message input so there isn't anything nasty in
                      > it before using the submitted info. (In this case, you may want to do
                      > something like strip_tags() on it since it's not an HTML MIME message.)[/color]

                      So, if I wanted to mail the author and point out that
                      "the <body> and </head> tags are incorrectly nested", he'd
                      read that "the and tags are incorrectly nested". That's
                      worse than useless.
                      [color=blue]
                      > Best to get in the practice of validating/filtering input and output
                      > from the beginning - event if it isn't necessary. It will save you a lot
                      > of headaches down the road...[/color]

                      Yes, but blindly deleting content for no apparent
                      reason is not much of an improvement.


                      --n

                      Comment

                      • DJ Craig

                        #12
                        Re: new to php

                        You could use html_entities() instead of strip_tags():
                        Convert all applicable characters to HTML entities

                        Then if you send the email as an HTML email the reader will display it
                        right. Or if you are confortable with HTML entities you could still
                        just send it as a plain text email. I can't see anything wrong with
                        that code, but like Andrew says, break it down into smaller parts.
                        BTW, instead of writing $HTTP_POST_VARS["message"] you could just write
                        $_POST['message']. Means the same thing.

                        Comment

                        • tammy4real2006@yahoo.com

                          #13
                          Re: new to php

                          fool

                          Comment

                          Working...