468,241 Members | 1,610 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,241 developers. It's quick & easy.

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 = wh*****@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.
Jan 24 '06 #1
7 1384
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
Jan 24 '06 #2
On Tue, 24 Jan 2006 09:59:22 +0100, "J.O. Aho" <us**@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

Jan 24 '06 #3
cover wrote:
On Tue, 24 Jan 2006 09:59:22 +0100, "J.O. Aho" <us**@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

Jan 24 '06 #4
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
<co****************@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>

Jan 25 '06 #5
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
<co****************@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.
js*******@attglobal.net
==================
Jan 25 '06 #6
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
<js*******@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?

Jan 26 '06 #7
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
<js*******@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?

Jan 26 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by jdph40 | last post: by
2 posts views Thread by Chuck | last post: by
4 posts views Thread by BernardNem via AccessMonster.com | last post: by
20 posts views Thread by paul814 | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.