Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Perl script calling in another Perl script

by focus310 (Novice)
on Feb 14, 2006 at 15:02 UTC ( [id://530132]=perlquestion: print w/replies, xml ) Need Help??

focus310 has asked for the wisdom of the Perl Monks concerning the following question:

Hello:

I have a form where a person has one of two options: pay using member account or pay online.

In my script, if a person chooses to pay online, it goes to a subroutine and does what it needs to do.

But, if a person chooses to pay using a member account, I want the script to send an email to the club and to the person who submitted the form. I want to use the formmail.pl script to process these emails.

Is it possible for me to redirect my script to another Perl script? If so, how?

Thanks in advance.
  • Comment on Perl script calling in another Perl script

Replies are listed 'Best First'.
Re: Perl script calling in another Perl script
by eXile (Priest) on Feb 14, 2006 at 16:02 UTC
    You can use $output = `$cmd` to call one script from the other, and can print $output after that finished (don't forget to do some decent errorhandling etc.). If the script you're calling that way uses CGI you can pass the arguments you want to pass to the script as key=value pairs (see documentation).

    Not sure if I like that solution, I think I'd go for 2 forms on the same page, one for paying online, one for using a member account.

Re: Perl script calling in another Perl script
by thedoe (Monk) on Feb 14, 2006 at 17:04 UTC

    If I remember correctly, formmail.pl is a basic email script from Matt's Script Archive.

    Personally, I would recommend building your own email within your submission script instead of calling formmail.pl. It is very easy to do, and you have much more control over the email. I would only recommend using formmail.pl if you have no knowledge of Perl and no interest in learning it. Since you are a member here, though, I assume you are interested in learning.

    I highly encourage you to have your own script send mail using MIME::Lite to build your email. The documentation is very straight forward, so you should be able to figure out how to build what you want very simply. MIME::Lite allows for very quick development of email messages with options that formmail.pl simply does not allow.

      Hi

      I actually have my email submission written in a Perl script. I hesitate to use it because I'm not sure if it is secure enough from people using the form for SPAM.

      If you would like, and I would be greatly appreciative, you can look at my email code and let me know what you think about the security issue. I could use some guidance. I'm fairly new to Perl so I know there's a lot to learn.

      I'm trying to be responsible with my coding so innocent people are hassled.

      I only posted the code up to the email confirmations. The rest of the code is an HTML page for confirming the registration as well as the paying online subroutine.

      Here's my code:
      #!/usr/bin/perl -Tw use CGI qw(:standard); use strict; use lib qw(/home/brmaster/www/); use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard escape escapeHTML); use Mail::Sendmail; my ($player, $parent, $memberid, $phone, $email, $dates, $event, $stre +et, $city, $state, $zip, $payment, $message); $player = param("player"); $parent = param("parent"); $memberid = param("memberid"); $phone = param("phone"); $email = param("email"); $dates = param("dates"); $event = param("event"); $street = param("street"); $city = param("city"); $state = param("state"); $zip = param("zip"); $message = param("message"); $payment = param("payment"); print header, start_html "\n"; my $choice = param ("choice"); if (($choice eq "Submit") && ($payment eq "Please bill my Bridgemill a +ccount")|| ($payment eq "Prefer to mail payment with this form")) { send_confirmation_email (); reg_form_info_page (); send_submit_email (); } elsif (($choice eq "Submit") && ($payment eq "Pay online with credit c +ard")) { send_confirmation_email (); send_submit_email (); paypal_page (); } else { print p ("Logic error, unknown choice: $choice"); } #@ SEND_CONFIRMATION_EMAIL sub send_confirmation_email { my %mail = ( From => "support\@bridgemilltennis.com", # YOU SHOU +LD CHANGE THIS! To => $email, Subject => "Registration for Power Tennis Summer Camp Submitte +d", Message => "" ); my $page; $mail{Message} = <<EOF; Thank you for registering for the BridgeMill Power Tennis Summer Camp. This is the information you submitted. Player's Name: $player Parent's Name: $parent Telephone: $phone Email Address: $email Camp Date(s): $dates Event: $event Street: $street City: $city State: $state Zip Code: $zip Method of Payment: $payment Message: $message EOF sendmail (%mail) or $page .= p (escapeHTML ("Oops, failure sending mail to $mai +l{To}")); return (defined ($page) ? $page : ""); } #@ SEND_CONFIRMATION_EMAIL #@ SEND_SUBMIT_EMAIL sub send_submit_email { my %mail = ( From => $email, To => "support\@bridgemilltennis.com", # YOU SHOULD CHA +NGE THIS! Subject => "Power Tennis Summer Camp Registration Submitted", Message => "" ); my $page; $mail{Message} = <<EOF; The following player, $player, has submitted the Power Tennis Summer C +amp registration form. Player's Name: $player Parent's Name: $parent Telephone: $phone Email Address: $email Camp Date(s): $dates Event: $event Street: $street City: $city State: $state Zip Code: $zip Method of Payment: $payment Message: $message EOF sendmail (%mail) or $page .= p (escapeHTML ("Oops, failure sending mail to $mai +l{To}")); return (defined ($page) ? $page : ""); } #@ SEND_SUBMIT_EMAIL

        Using a email module like NET::SMTP or your example above can provide a more secure solution for you.

        If you primary concern is to prevent spam:

      • Don't have an smtp server running unless your are hosting your own and know what you're doing.
      • Hard code the email addresses (to address and from address) in your script rather than allowing user controlled inputs. This way, even if someone does abuse the script, they won't be able to specify where the email is going.
      • Make sure that the only interface to your mailer is a web page. Worst case, if some script kiddie is spamming your box with mail, you have the weblogs and can have his isp to turn off the account.
Re: Perl script calling in another Perl script
by explorer (Chaplain) on Feb 14, 2006 at 17:59 UTC
    Please, don't use the Matt's scripts.

    Connect to nms project and use these versions of formmail and others.
      Hi,

      I am using the nms formmail.pl script. I've been warned about Matt's script.
Re: Perl script calling in another Perl script
by beachbum (Beadle) on Feb 14, 2006 at 16:11 UTC

    I may be the only one, but I'm not familiar with a script called formmail.pl. I checked CPAN, and didn't see it there either.

    I'm not sure that you can expect to get help with a script unless you provide the inputs and outputs of that script, or post the code itself.

    Assuming that this is a web application that you are building, and that formmail.pl is some script that you've found that uses HTTP POSTs to send email: I would suggest that you look at building a form on your original page, setting the values using javascript, CGI, or maybe HTTP GETs, then redirecting to formmail.pl using those values you set. In javascript, this would be a document.form.submit where 'form' is the name of your html form.

    How do I post a question effectively?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://530132]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-25 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found