Home > Archive > PHP Language > January 2006 > Emailing Form Data
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
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.
| |
| J.O. Aho 2006-01-24, 3:55 am |
| 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
| |
|
| 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
| |
| Philip Ronan 2006-01-24, 6:56 pm |
| cover wrote:
[color=darkred]
> On Tue, 24 Jan 2006 09:59:22 +0100, "J.O. Aho" <user@example.net>
> wrote:
>
> Did the trick - thanks :-)
>
Before you rest on your laurels, please read up on email header injection.
Your script is a potential spam factory.
<http://securephp.damonkohler.com/in...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
| |
|
| 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>
| |
| Jerry Stuckle 2006-01-25, 6:57 pm |
| cover wrote:[color=darkred]
> 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:
>
>
>
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
==================
| |
|
| 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?
| |
|
| 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
[color=darkred]
> 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:
>
>
|
|
|
|
|