Bluehost.com Web Hosting $6.95

Emailing Form Data

This is a discussion on Emailing Form Data within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I have a form that writes to an MySQL database just fine but would like to email people to give ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-24-2006
cover
 
Posts: n/a
Default 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@servername.com

My input form is as follows:
<form action="process2.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:<textarea 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($from);
$to = stripslashes($to);
$subject = stripslashes($subject);
$message = stripslashes($message);
mail('$to',$from,$subject,$message);
header("location: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.
Reply With Quote
  #2 (permalink)  
Old 01-24-2006
J.O. Aho
 
Posts: n/a
Default Re: Emailing Form Data

cover wrote:

<?php
@extract($_POST);
/* > $from = stripslashes($from); */
$from = stripslashes($from)."\r\n";
$to = stripslashes($to);
$subject = stripslashes($subject);
$message = stripslashes($message);
/* > mail('$to',$from,$subject,$message); */
mail($to,$subject,$message,$from);
header("location:process.php");
?>


//Aho
Reply With Quote
  #3 (permalink)  
Old 01-24-2006
cover
 
Posts: n/a
Default Re: Emailing Form Data

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

Did the trick - thanks :-)

><?php
>@extract($_POST);
>/* > $from = stripslashes($from); */
>$from = stripslashes($from)."\r\n";
>$to = stripslashes($to);
>$subject = stripslashes($subject);
>$message = stripslashes($message);
>/* > mail('$to',$from,$subject,$message); */
>mail($to,$subject,$message,$from);
>header("location:process.php");
>?>
>
>
> //Aho

Reply With Quote
  #4 (permalink)  
Old 01-24-2006
Philip Ronan
 
Posts: n/a
Default Re: Emailing Form Data

cover wrote:

> On Tue, 24 Jan 2006 09:59:22 +0100, "J.O. Aho" <user@example.net>
> wrote:
>
> Did the trick - thanks :-)
>
>> <?php
>> @extract($_POST);
>> /* > $from = stripslashes($from); */
>> $from = stripslashes($from)."\r\n";
>> $to = stripslashes($to);
>> $subject = stripslashes($subject);
>> $message = stripslashes($message);
>> /* > mail('$to',$from,$subject,$message); */
>> mail($to,$subject,$message,$from);
>> header("location:process.php");
>> ?>


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

<http://securephp.damonkohler.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

Reply With Quote
  #5 (permalink)  
Old 01-25-2006
cover
 
Posts: n/a
Default 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="process2.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="process3.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
<coverlandNOSPAM914@yahoo.com> wrote:


>My input form is as follows:
><form action="process2.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:<textarea name="text" name="message" cols="50"
>rows="10"></textarea><br />
><input type="submit" name="submit" value="Send" />
></form>

Reply With Quote
  #6 (permalink)  
Old 01-25-2006
Jerry Stuckle
 
Posts: n/a
Default Re: Emailing Form Data

cover wrote:
> 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="process2.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="process3.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
> <coverlandNOSPAM914@yahoo.com> wrote:
>
>
>
>>My input form is as follows:
>><form action="process2.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:<textarea name="text" name="message" cols="50"
>>rows="10"></textarea><br />
>><input type="submit" name="submit" value="Send" />
>></form>


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@attglobal.net
==================
Reply With Quote
  #7 (permalink)  
Old 01-26-2006
cover
 
Posts: n/a
Default 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="process2.php" method="post">
<form action="process3.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:<textarea 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@attglobal.net> wrote:

>
>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?

Reply With Quote
  #8 (permalink)  
Old 01-26-2006
Barry
 
Posts: n/a
Default Re: Emailing Form Data

cover wrote:
> 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="process2.php" method="post">
> <form action="process3.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:<textarea name="text" name="message" cols="50"
> rows="10"></textarea><br />
> <input type="submit" name="submit" value="Send" />
> </form>
>


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

> 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@attglobal.net> wrote:
>
>
>>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?

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:45 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0