Solved

Help to modify perl/cgi script

Posted on 2001-06-21
8
324 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
ID: 6213500
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
ID: 6213789
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
ID: 6213882
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
ID: 6213915
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:mehdi
ID: 6215217
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
ID: 6218861
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
ID: 6219253
Hi

specify your filehandle.

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

Author Comment

by:mtech
ID: 6243926
mehdi

thanks for the help - got it all working ok

mtech
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
compress files in RAR using perl 13 79
stftime format 4 55
Parse csv file and generate graphs in HTML in bash 8 158
Matching a random pattern with one common character 2 45
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

17 Experts available now in Live!

Get 1:1 Help Now