Forum Moderators: coopster & phranque

Message Too Old, No Replies

I need a Form to email that keeps track of all data.

Sends the form data and saves it to the server.

         

werty

4:01 pm on Oct 24, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I am looking to get my hands on a form to email script that also keeps track of all the data submitted through the form. Does anyone know of one?

I searched G for it and had no luck.

The reason I want this is that people have submitted our form online and we never get an email. Once was due to our mailserver being down. The other times I am not sure.

So my goal is to be able to have a backup(on the server), of all form info that has been submittedjust incase we never get the email that is sent by the form to email script.

Also the reason I know that the form was submitted is that I have a "post" entry in my logs follwed by the thank-you.html page being delivered to the user.

Thanks in advance.

jatar_k

7:31 am on Oct 29, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



sorry this went with out an answer werty, did you find anything?

It shouldn't be overly difficult to have a script write to a file before it emails. A nice comma delimited list of submitted values should work nicely. I can't really suggest code unless you want php. ;)

In any case this should act as a shameless mod bump and a little encouragement for a simple solution or point in the right direction.

werty

8:18 am on Oct 29, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I am yet to find one. I am pretty worthless when it comes to programming.

I think I have one on one of my old servers, It is just a matter of finding which server, and what it is called.

timk

5:31 pm on Oct 29, 2003 (gmt 0)

10+ Year Member



use Net::SMTP ;
$smtp = Net::SMTP->new("smtp.your.domain.com") ;
$smtp->mail("sender\@your.domain.com") ;
$smtp->to("recipient\@their.domain.com") ;
$smtp->data() ;
$smtp->datasend("To: recipient\@their.domain.com\n");
$smtp->datasend("Subject: What Ever you Want\n");
$smtp->datasend("\n");
$smtp->datasend("Just fill this in\n");
$smtp->dataend() ;
$smtp->quit() ;

#just add the following lines.
open(INF,">>C:/backup/of/server/dir/email.txt");
print INF "$email, or whatever your variables are from your form\n";
close(INF);

werty

8:11 pm on Oct 29, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Timk, thank you, can you please explain that, it seems to be a few hundred feet over my head?

I know smtp is something to with the mail server?

Is this: use Net::SMTP ; something I would do in the shell?

#just add the following lines.

Add them to the webpage with the form? Or to the existing script?

Thanks again.

sugarkane

10:51 am on Nov 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Timk, welcome to WebmasterWorld and thanks for your example.

werty, an alternative approach would be something along these lines:

#!/usr/bin/perl

use CGI;
$query=CGI::new();
@params=$query->param(); # Get the form field names

# Open a pipe to the mail program and print headers
open (MAIL, "¦ /usr/bin/sendmail -t") or die "Couldn't open email prog\n";
print MAIL "To: foo\@example.com\n"; # where to send the data too
print MAIL "From: website\@example.com\n";
print MAIL "Subject: Form Results\n\n";

# Open up a data file using append
open(FILE, ">>data.txt") or die "Couldn't open data file\n";

# print all form name/value pairs to both email and data file
foreach $i (@params) {
$value=$query->param($i);
print FILE "$i : $value\n";
print MAIL "$i : $value,";
}

# Close up the file and email pointers
print FILE "\n";
close(FILE);
print MAIL "\n.\n";
close (MAIL);

# finish
print "content-type: text/html\n\n";
print qq^
<html>
Add your 'thank you' html here...
</html>
^;
exit;

That basic script will forward all form data to the specified email address, and store it (one form per line) in data.txt

However, it doesn't do any sanity checking on data so you *might* have problems if the form data contains commas or \n characters - but if the file is just for backup purposes rather than for importing into another program, then it's probably not that much of an issue.