Getting Info From a Form Mailed
Getting Info From a Form Mailed
am 01.03.2006 23:57:10 von mw
I am relatively new to perl (had a little exposure - mostly I use
PHP), but I would like to learn how to put a few lines of code into a
script so that a web form submitted to that script has it's data
emailed to me.
What would be my best resources for learning that?
Thanks,
MR
Re: Getting Info From a Form Mailed
am 02.03.2006 00:07:49 von Gunnar Hjalmarsson
MW wrote:
> I am relatively new to perl (had a little exposure - mostly I use
> PHP), but I would like to learn how to put a few lines of code into a
> script so that a web form submitted to that script has it's data
> emailed to me.
Why don't you do it in PHP if that's the language you know best?
> What would be my best resources for learning that?
http://www.cgi.resourceindex.com/Documentation/CGI_Tutorials /
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Re: Getting Info From a Form Mailed
am 02.03.2006 00:23:56 von mw
On Thu, 02 Mar 2006 00:07:49 +0100, Gunnar Hjalmarsson
wrote:
>MW wrote:
>> I am relatively new to perl (had a little exposure - mostly I use
>> PHP), but I would like to learn how to put a few lines of code into a
>> script so that a web form submitted to that script has it's data
>> emailed to me.
>
>Why don't you do it in PHP if that's the language you know best?
>
>> What would be my best resources for learning that?
>
>http://www.cgi.resourceindex.com/Documentation/CGI_Tutorial s/
There is a script attached to the form that already processes it (puts
data in a file, etc), but I would like to be notified whenever that
happens.
Thanks,
-MR
Re: Getting Info From a Form Mailed
am 02.03.2006 00:32:57 von Matt Garrish
"MW" wrote in message
news:r6bc02dk214ant6m6ssuhgevc946hvgitc@4ax.com...
> On Thu, 02 Mar 2006 00:07:49 +0100, Gunnar Hjalmarsson
> wrote:
>
>>MW wrote:
>>> I am relatively new to perl (had a little exposure - mostly I use
>>> PHP), but I would like to learn how to put a few lines of code into a
>>> script so that a web form submitted to that script has it's data
>>> emailed to me.
>>
>>Why don't you do it in PHP if that's the language you know best?
>>
>>> What would be my best resources for learning that?
>>
>>http://www.cgi.resourceindex.com/Documentation/CGI_Tutoria ls/
>
> There is a script attached to the form that already processes it (puts
> data in a file, etc), but I would like to be notified whenever that
> happens.
>
Take a look at Net::SMTP, Mail::Mailer, or one of the other mail modules on
cpan. If you have an existing script I'm sure you can figure out how to hack
a few more lines in to fire off an email. Just make sure your server
supports the module you pick. The documentation for the modules should be
all you need to get going.
Matt
Re: Getting Info From a Form Mailed
am 02.03.2006 01:22:04 von mw
On Wed, 1 Mar 2006 18:32:57 -0500, "Matt Garrish"
wrote:
>Take a look at Net::SMTP, Mail::Mailer, or one of the other mail modules on
>cpan. If you have an existing script I'm sure you can figure out how to hack
>a few more lines in to fire off an email. Just make sure your server
>supports the module you pick. The documentation for the modules should be
>all you need to get going.
>
Sorry to be stupid here, but what is cpan?
Thanks,
-MR
Re: Getting Info From a Form Mailed
am 02.03.2006 01:39:29 von Jim Gibson
In article , MW
wrote:
> On Wed, 1 Mar 2006 18:32:57 -0500, "Matt Garrish"
> wrote:
>
>
> >Take a look at Net::SMTP, Mail::Mailer, or one of the other mail modules on
> >cpan. If you have an existing script I'm sure you can figure out how to hack
> >a few more lines in to fire off an email. Just make sure your server
> >supports the module you pick. The documentation for the modules should be
> >all you need to get going.
> >
>
> Sorry to be stupid here, but what is cpan?
>
> Thanks,
>
> -MR
>
Comprehensive Perl Archive Network.
It is a repository of freely-available Perl modules and the Perl
language itself. Go to www.cpan.org.
The commands
sudo perl -MCPAN -e shell
cpan> install Net::SMTP
cpan> q
will install the Net::SMTP module on your system if your system is
unix. Other platforms might be different.
perldoc Net::SMTP will get you the documentation for the Net::SMTP
module if it has been installed on your system. The documentation is
also available at the CPAN website.
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Re: Getting Info From a Form Mailed
am 02.03.2006 19:38:00 von mw
Ok, now I am stuck on this:
I want to confirm a form has been filled out before the data gets
processed.
What would I call to do that? I imagine it would be an 'if' statement
with an 'exists' in it, but i am stumped as to what I would be
checking.
Basically I have a form on a page, but I don't want the processing to
take place until after the form has been filled out - and I figure the
best way to do that would be to check a POST variable, but I am having
problems trying to come up with that method.
Any help is appreciated!
Thanks,
MW
Re: Getting Info From a Form Mailed
am 03.03.2006 14:41:02 von Paul Lalli
MW wrote:
> Ok, now I am stuck on this:
>
>
> I want to confirm a form has been filled out before the data gets
> processed.
>
> What would I call to do that? I imagine it would be an 'if' statement
> with an 'exists' in it, but i am stumped as to what I would be
> checking.
>
> Basically I have a form on a page, but I don't want the processing to
> take place until after the form has been filled out - and I figure the
> best way to do that would be to check a POST variable, but I am having
> problems trying to come up with that method.
>
The CGI.pm param() function takes the name of a field as an argument,
and returns the value of the field. If no such parameter was passed
in, it returns undef;
use CGI qw/:standard/;
if (! param('name') ){
exit_with_error("You forgot to type your name!!");
}
Please read up on using CGI:
perldoc CGI
Paul Lalli
Re: Getting Info From a Form Mailed
am 03.03.2006 17:55:25 von mw
Thanks for your advice, I've put together a script, but I have not
been able to get it to spit out the variables. Here is what I have.
The form is with the POST method, the variable names ("first", "last")
are correct.
Basically, this sends me an email, but the variables, first and last
name are blank! The writing before it appears, though.
use CGI qw/:standard/;
if (! param('pass') ){
open (MAIL, "|/usr/sbin/sendmail -oi -t ")
or &dienice("Can't fork for sendmail: $!\n");
my $recipient = 'michael@romagnoli.us';
print MAIL "To: $recipient\n";
print MAIL "From: forms@romagnoli.us\n";
print MAIL "Subject: Usermin Form\n\n";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
# Starts fixing the data up
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/
pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
print MAIL "First Name = ", $FORM{'first'}, "\n";
print MAIL "Last Name = ", $FORM{'last'}, "\n";
close(MAIL);
}
Any input for this perl newbie would be appreciated!
thanks again,
MR
Re: Getting Info From a Form Mailed
am 03.03.2006 19:57:56 von Paul Lalli
MW wrote:
> Thanks for your advice,
Why are you thanking me for advice that you *completely* ignored?
> I've put together a script, but I have not
> been able to get it to spit out the variables. Here is what I have.
> The form is with the POST method, the variable names ("first", "last")
> are correct.
How are you determining that? Your only evidence about this process is
a script that doesn't work correctly, that prints out blanks for the
first and last fields. So how do you know they're set correctly?
> Basically, this sends me an email, but the variables, first and last
> name are blank! The writing before it appears, though.
>
> use CGI qw/:standard/;
Are you using
use strict;
use warnings;
use CGI::Carp qw/fatalsToBrowser/;
?
If not, why not?
> if (! param('pass') ){
>
> open (MAIL, "|/usr/sbin/sendmail -oi -t ")
> or &dienice("Can't fork for sendmail: $!\n");
>
> my $recipient = 'michael@romagnoli.us';
>
> print MAIL "To: $recipient\n";
>
> print MAIL "From: forms@romagnoli.us\n";
I don't believe for a second that that works as you want it to.
> print MAIL "Subject: Usermin Form\n\n";
>
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>
>
> @pairs = split(/&/, $buffer);
>
> # Starts fixing the data up
> foreach $pair (@pairs) {
> ($name, $value) = split(/=/, $pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/
> pack("C", hex($1))/eg;
> $FORM{$name} = $value;
> }
This has been shown time and time again to be a bad idea. Do not copy
and paste code. Read and understand. Go read the document I told you
to read the last time. Do not randomly copy examples from the web or
from other broken code. This solution you've copied and pasted is
broken.
perldoc CGI
Again.
> print MAIL "First Name = ", $FORM{'first'}, "\n";
print MAIL "First Name = ", param('first'), "\n";
> print MAIL "Last Name = ", $FORM{'last'}, "\n";
print MAIL "Last Name = ", param('last'), "\n";
Paul Lalli