Solved

Help to modify perl/cgi script

Posted on 2001-06-21
8
322 Views
Last Modified: 2011-09-20
I have an email form that is being moved to a different ISP. The new ISP provides your own CGI area and some sample CGI scripts to use. I need to modify the sample code so that it will work with my form. Can someone help.

the CGI/PERL is:

# This script:
#
# - Takes the form contents
# - Saves the message into a temporary file
# - Calls Blat to send the mail
#


# Use the cgi unit
use cgi;

# Get the values from the form
$form = new CGI;
$sname=$form->param('sendername');
$saddr=$form->param('senderaddr');
$rname=$form->param('recipientname');
$raddr=$form->param('recipientaddr');
$subject=$form->param('subject');

$server="smtp.fasthosts.co.uk";
$message=$form->param('message');

$lt='<';
$gt='>';

# Output the correct header
print "Content-type: text/html\n\n";

# Save the message into a text file
open (messtxt,">message.txt");
print messtxt ($message);
close messtxt;

# Build the Blat command line and execute it
$blat="blat.exe message.txt -s \"$subject\" -t \"$lt$raddr$gt$rname\" -server $server -f \"$lt$saddr$gt$sname\"";

system($blat);

print $blat;
print "<br><br>Done.<br><br>";
print "Mail sent to $raddr.";
=========================================================

and my html form is:

<form method="POST" action="http://www.mtech-csl.co.uk/cgi-bin/FormMail.pl" name="frmbuy">
  <input type="hidden" name="recipient" value="martin@mtech-csl.co.uk">
  <input type="hidden" name="sort" value="order:name,email,phone,address,requirements,txtItems">
  <input type="hidden" name="required" value="name,email,phone,address">
  <input type=hidden name="subject" value="MacRo Graphics Web Order">
  <input type="hidden" name="redirect" value="http://www.mtech-csl.co.uk/designs/submit_ok.htm">
  <table width="400" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td valign="top">Name:</td>
      <td valign="top">
        <input type="text" name="name" size="40">
      </td>
    </tr>
    <tr>
      <td valign="top">Email:</td>
      <td valign="top">
        <input type="text" name="email" size="50">
      </td>
    </tr>
    <tr>
      <td valign="top">Telephone:</td>
      <td valign="top">
        <input type="text" name="phone" size="30">
      </td>
    </tr>
    <tr>
      <td valign="top">Address:</td>
      <td valign="top">
        <textarea name="address" cols="50" rows="6"></textarea>
      </td>
    </tr>
    <tr>
      <td valign="top">Special<br>
        Requirements: </td>
      <td valign="top">
        <textarea name="requirements" cols="50" rows="4"></textarea>
      </td>
    </tr>
    <tr>
      <td valign="top">Order Items:</td>
      <td valign="top">
        <textarea name=txtItems cols=50 rows=15></textarea>
      </td>
    </tr>
  </table>
 
  <p><input type="submit" value="Send Order" name="SendForm">
</form>
0
Comment
Question by:mtech
  • 4
  • 4
8 Comments
 
LVL 1

Expert Comment

by:mehdi
Comment Utility
If this *was* working on the previous hosts machine, and there has been no change in terms of the OS, then make sure..

$form->param('this_param'); make sure these are all correct and ALL this_param's match up with what you have in your form.

make sure that you have write permissions for writing to the file you are writing to.

If it doesnt just work, then post the error message from the log file, or try

use CGI::Carp 'fatalsToBrowser';

[should give you an error message on your browser instead of completelly useless internal server error :)

choochoo..

Mehdi
0
 
LVL 1

Author Comment

by:mtech
Comment Utility
Sorry Mehdi

Maybe I did not make this clear. The script used by the old ISP is NOT the same as the new one. I need to edit the new script to work with my form. At my old ISP I did not have CGI access and so do not have the script that was called in my page.

Does this make sense

mtech

0
 
LVL 1

Expert Comment

by:mehdi
Comment Utility
ok.. if the Perl script there is the one from your new ISP, then the script should work fine.  Make sure that in your HTML your fields match up with the Perl CGI requests.. in other words

Your html

please give your name: <input type="text" name="sendername">

.. so you have to have sendername in the perl [safer for you to change the html to match the perl rather that doing the reverse]

$sname=$form->param('sendername');

If anything is going wrong, the error log will tell you what

regs,

Mehdi
0
 
LVL 1

Author Comment

by:mtech
Comment Utility
Mehdi

Does that mean that there should be an entry in the perl for each form item, if so this means I will need to add some extra ones? If they are added do they just go at the top where the others are or do they need added somewhere else in the script as well (i.e. in the 'blat' command line)?
mtech
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Expert Comment

by:mehdi
Comment Utility
yes, you need to catch the extra fields.. also add them to the text file

$housenumber=$form->param(housenumber');
.
.
.

print messtxt ($message);
print "\n";                  #new line in the file maybe ?
print messtxt ($housenumber);

so now yur adding your extra fields also.

the blat line seems to take the contents of the file.. look where you have :

blat.exe message.txt # this is the file you wrote the
                     # contents of the form to.

so try adding the extra fields to the text file, blat should sent the contents of that file.

good luck with it :)

Mehdi
0
 
LVL 1

Author Comment

by:mtech
Comment Utility
Mehdi

Thanks - I will not be able to try it out til early next week however when the file is opened, written to and closed as below:

  open (messtxt,">message.txt");
  print messtxt ($message);
  close messtxt;

if I want to write some additional text to the file do I use:

  print "The text I want";

or should it be:

  print messtxt "The text I want";

many thanks
mtech
0
 
LVL 1

Accepted Solution

by:
mehdi earned 50 total points
Comment Utility
Hi

specify your filehandle.

print messtxt "The text I want";
0
 
LVL 1

Author Comment

by:mtech
Comment Utility
mehdi

thanks for the help - got it all working ok

mtech
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now