?
Solved

Help with PERL forms

Posted on 1999-11-01
7
Medium Priority
?
168 Views
Last Modified: 2010-03-05
How would I go about programming a PERL script that submits
a form and mails it to me?

I would like a working script (if possible).  I am going to write my own, but it would be helpful to have a script (described step-by-step) that I can use as a reference.  

Thanks,

Ace~
0
Comment
Question by:Topace
  • 3
  • 3
7 Comments
 
LVL 2

Accepted Solution

by:
sanek earned 900 total points
ID: 2174833
Submits using GET method.
#!/usr/local/bin/perl5 -w

# use helpful pm's
use LWP::Simple;
use URI::URL;

my $url = url('http://some.website.com/cgi-bin/some.cgi');
$url->query_form(
param_no_1 => "param1",
param_no_2 => "param2"
);

$content = get($url);

# now mail the content to you.
open( SENDMAIL, '| /usr/sbin/sendmail -oi -n -t') || die "Cannot open sendmail!";
print SENDMAIL <<MESSAGE;
From: script\@domain.com
To: your_mail\@domain.com
Subject: submitted form

$content
MESSAGE

close (SENDMAIL);
0
 
LVL 1

Author Comment

by:Topace
ID: 2197314
Hmmm... this looks good, but could you explain it a little for me?  I'm kinda a rookie at PERL Programming on the Web.  

Thanks,
Ace~
0
 
LVL 85

Expert Comment

by:ozo
ID: 2198019
What do you wish to have explained?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Expert Comment

by:sanek
ID: 2198052
my $url = url('http://some.website.com/cgi-bin/some.cgi');
$url->query_form(
      param_no_1 => "param1",
      param_no_2 => "param2"
      );
$content = get($url);

These lines retreive content outputted by CGI $url.

Next lines use sendmail program to send you $content.
We have to construct mail body (to specify To, From, Subject and body fields).

Anything in particular you want to ask?
0
 
LVL 1

Author Comment

by:Topace
ID: 2201112
So, does
$url->query_form(
                param_no_1 => "param1",
                param_no_2 => "param2"

just parse the information gotten from the script?  

open( SENDMAIL, '| /usr/sbin/sendmail -oi -n -t')
This line opens SENDMAIL, what do the -oi -n -t extensions do?

finally...
if sendmail is the filehandle opened, what is
print SENDMAIL <<MESSAGE; ?

Is MESSAGE the message from the form?

Also -- what if my server doesn't support SENDMAIL? I am not sure, but I will find out.  

Ace~
0
 
LVL 2

Expert Comment

by:sanek
ID: 2201331
$url->query_form(
                     param_no_1 => "param1",
                     param_no_2 => "param2" );
does not PARSE information, it's just SETS fields in request to
CGI.

I'm not sure what switches -oi -n -t  do, I've just took it from
working script. You can find about senmail by 'man sendmail'.

$a = 4;
print <<SOME_LABEL; # Variation of Perl command
Text will be printed, until SOME_LABEL label is reached.
Varibales will be evaluated \$a=$a;
SOME_LABEL

Thus, "print SENDMAIL <<MESSAGE; "
just prints following it text to sendmail.
0
 
LVL 1

Author Comment

by:Topace
ID: 2211445
Thank you, I believe I can figure out what I want to do from here.

Ace~
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question