Emailing Form Data

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

    #1

    Emailing Form Data

    I have a form that writes to an MySQL database just fine but would
    like to email people to give them a heads up that an entry was made
    under their name (1 of 6 names on writing to the database). This
    server exists on an intranet and would have no 'web' function other
    than using possibly the existing email server.

    Is all that I need to do to make this happen, to change php.ini as
    follows:

    [mail function]
    ; For Win32 only.
    SMTP = mail.servername .com
    smtp_port = 25

    ; For Win32 only.
    ;sendmail_from = whoever@servern ame.com

    My input form is as follows:
    <form action="process 2.php" method="post">
    From: <input type="text" name="from" size="20" maxlength="20" /><br />
    To: <input type="text" name="to" size="30" maxlength="30" /><br />
    Subject: <input type="text" name="subject" size="30" maxlength="30"
    /><br />
    Message:<textar ea name="text" name="message" cols="50"
    rows="10"></textarea><br />
    <input type="submit" name="submit" value="Send" />
    </form>

    and passes data to process2.php as shown in form 1:
    <?php
    @extract($_POST );
    $from = stripslashes($f rom);
    $to = stripslashes($t o);
    $subject = stripslashes($s ubject);
    $message = stripslashes($m essage);
    mail('$to',$fro m,$subject,$mes sage);
    header("locatio n:process.php") ;
    ?>

    This worked through my testbed on my SMTP 'once' and only sort of,
    once so I might be missing something. :-) TIA for any help.
  • J.O. Aho

    #2
    Re: Emailing Form Data

    cover wrote:

    <?php
    @extract($_POST );
    /* > $from = stripslashes($f rom); */
    $from = stripslashes($f rom)."\r\n";
    $to = stripslashes($t o);
    $subject = stripslashes($s ubject);
    $message = stripslashes($m essage);
    /* > mail('$to',$fro m,$subject,$mes sage); */
    mail($to,$subje ct,$message,$fr om);
    header("locatio n:process.php") ;
    ?>


    //Aho

    Comment

    • cover

      #3
      Re: Emailing Form Data

      On Tue, 24 Jan 2006 09:59:22 +0100, "J.O. Aho" <user@example.n et>
      wrote:

      Did the trick - thanks :-)
      [color=blue]
      ><?php
      >@extract($_POS T);
      >/* > $from = stripslashes($f rom); */
      >$from = stripslashes($f rom)."\r\n";
      >$to = stripslashes($t o);
      >$subject = stripslashes($s ubject);
      >$message = stripslashes($m essage);
      >/* > mail('$to',$fro m,$subject,$mes sage); */
      >mail($to,$subj ect,$message,$f rom);
      >header("locati on:process.php" );
      >?>
      >
      >
      > //Aho[/color]

      Comment

      • Philip Ronan

        #4
        Re: Emailing Form Data

        cover wrote:
        [color=blue]
        > On Tue, 24 Jan 2006 09:59:22 +0100, "J.O. Aho" <user@example.n et>
        > wrote:
        >
        > Did the trick - thanks :-)
        >[color=green]
        >> <?php
        >> @extract($_POST );
        >> /* > $from = stripslashes($f rom); */
        >> $from = stripslashes($f rom)."\r\n";
        >> $to = stripslashes($t o);
        >> $subject = stripslashes($s ubject);
        >> $message = stripslashes($m essage);
        >> /* > mail('$to',$fro m,$subject,$mes sage); */
        >> mail($to,$subje ct,$message,$fr om);
        >> header("locatio n:process.php") ;
        >> ?>[/color][/color]

        Before you rest on your laurels, please read up on email header injection.
        Your script is a potential spam factory.

        <http://securephp.damon kohler.com/index.php/Email_Injection >

        You might also want to replace "\r\n" with "\n" in the additional headers. I
        know this isn't what it says in the RFCs, but it's the de facto standard now.
        If you put carriage returns into the header of an email, it's more likely to
        be flagged as spam.

        --
        philronan [@] blueyonder [dot] co [dot] uk

        Comment

        • cover

          #5
          Re: Emailing Form Data

          A follow up question:

          Writing values to the db with the MySQL query INSERT INTO code doesn't
          like sharing with the code that initiates the email so, is it common
          practice to initiate TWO actions from the input form shown below? i.e.
          to use <form action="process 2.php" method="post"> twice in a row on
          the input form? Once for example to initiate INSERT INTO the database
          and the second <form action="process 3.php" method="post"> right below
          it to initiate the email code on process3.php? Seems like a pretty
          clean way of dealing with it, thoughts anyone? Otherwise I need to
          figure out how to do the INSERT INTO and then continue on to
          initiating the email code. Thanks very much.

          On Mon, 23 Jan 2006 20:54:34 -0800, cover
          <coverlandNOSPA M914@yahoo.com> wrote:

          [color=blue]
          >My input form is as follows:
          ><form action="process 2.php" method="post">
          >From: <input type="text" name="from" size="20" maxlength="20" /><br />
          >To: <input type="text" name="to" size="30" maxlength="30" /><br />
          >Subject: <input type="text" name="subject" size="30" maxlength="30"
          >/><br />
          >Message:<texta rea name="text" name="message" cols="50"
          >rows="10"></textarea><br />
          ><input type="submit" name="submit" value="Send" />
          ></form>[/color]

          Comment

          • Jerry Stuckle

            #6
            Re: Emailing Form Data

            cover wrote:[color=blue]
            > A follow up question:
            >
            > Writing values to the db with the MySQL query INSERT INTO code doesn't
            > like sharing with the code that initiates the email so, is it common
            > practice to initiate TWO actions from the input form shown below? i.e.
            > to use <form action="process 2.php" method="post"> twice in a row on
            > the input form? Once for example to initiate INSERT INTO the database
            > and the second <form action="process 3.php" method="post"> right below
            > it to initiate the email code on process3.php? Seems like a pretty
            > clean way of dealing with it, thoughts anyone? Otherwise I need to
            > figure out how to do the INSERT INTO and then continue on to
            > initiating the email code. Thanks very much.
            >
            > On Mon, 23 Jan 2006 20:54:34 -0800, cover
            > <coverlandNOSPA M914@yahoo.com> wrote:
            >
            >
            >[color=green]
            >>My input form is as follows:
            >><form action="process 2.php" method="post">
            >>From: <input type="text" name="from" size="20" maxlength="20" /><br />
            >>To: <input type="text" name="to" size="30" maxlength="30" /><br />
            >>Subject: <input type="text" name="subject" size="30" maxlength="30"
            >>/><br />
            >>Message:<text area name="text" name="message" cols="50"
            >>rows="10"></textarea><br />
            >><input type="submit" name="submit" value="Send" />
            >></form>[/color][/color]

            Rather, I'd look into what problem you're having with both sending the
            email and inserting into the database. It should work OK.

            Having two different forms means the user would have to click on two
            buttons in order. What if he only clicks on one of them?



            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • cover

              #7
              Re: Emailing Form Data

              Actually what I'm wanting to do is input the data into a MySQL
              database (which I have done successfully) and also email data off that
              form through a mail server at the same time (which I have done
              successfully separately - in other words, I haven't achieved both
              results off a single click of the 'submit' button). BUT...

              Shouldn't doing a form action / method="post" twice in the same form
              send the info in both directions as below?

              <form action="process 2.php" method="post">
              <form action="process 3.php" method="post">
              From: <input type="text" name="from" size="20" maxlength="20" /><br />
              To: <input type="text" name="to" size="30" maxlength="30" /><br />
              Subject: <input type="text" name="subject" size="30" maxlength="30"
              /><br />
              Message:<textar ea name="text" name="message" cols="50"
              rows="10"></textarea><br />
              <input type="submit" name="submit" value="Send" />
              </form>

              Also in taking the model to work, I discovered severe security over
              the email system so I'm looking to set up an SMTP mail server onto the
              server I've been working with - the work one will accept from this one
              if I can get it going. Am using Apache on a Windows server. Thanks
              for the reply Jerry...

              Chris


              On Wed, 25 Jan 2006 12:47:09 -0500, Jerry Stuckle
              <jstucklex@attg lobal.net> wrote:
              [color=blue]
              >
              >Rather, I'd look into what problem you're having with both sending the
              >email and inserting into the database. It should work OK.
              >
              >Having two different forms means the user would have to click on two
              >buttons in order. What if he only clicks on one of them?[/color]

              Comment

              • Barry

                #8
                Re: Emailing Form Data

                cover wrote:[color=blue]
                > Actually what I'm wanting to do is input the data into a MySQL
                > database (which I have done successfully) and also email data off that
                > form through a mail server at the same time (which I have done
                > successfully separately - in other words, I haven't achieved both
                > results off a single click of the 'submit' button). BUT...
                >
                > Shouldn't doing a form action / method="post" twice in the same form
                > send the info in both directions as below?
                >
                > <form action="process 2.php" method="post">
                > <form action="process 3.php" method="post">
                > From: <input type="text" name="from" size="20" maxlength="20" /><br />
                > To: <input type="text" name="to" size="30" maxlength="30" /><br />
                > Subject: <input type="text" name="subject" size="30" maxlength="30"
                > /><br />
                > Message:<textar ea name="text" name="message" cols="50"
                > rows="10"></textarea><br />
                > <input type="submit" name="submit" value="Send" />
                > </form>
                >[/color]

                Nope, it will only send it to one page.
                There should be no problem doing an insert and then mailing the data.
                Post your code so we can have a look at wots up.

                cheers
                Barry
                [color=blue]
                > Also in taking the model to work, I discovered severe security over
                > the email system so I'm looking to set up an SMTP mail server onto the
                > server I've been working with - the work one will accept from this one
                > if I can get it going. Am using Apache on a Windows server. Thanks
                > for the reply Jerry...
                >
                > Chris
                >
                >
                > On Wed, 25 Jan 2006 12:47:09 -0500, Jerry Stuckle
                > <jstucklex@attg lobal.net> wrote:
                >
                >[color=green]
                >>Rather, I'd look into what problem you're having with both sending the
                >>email and inserting into the database. It should work OK.
                >>
                >>Having two different forms means the user would have to click on two
                >>buttons in order. What if he only clicks on one of them?[/color][/color]

                Comment

                Working...