[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

Help to modify perl/cgi script

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
mtech
Asked:
mtech
  • 4
  • 4
1 Solution
 
mehdiCommented:
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
 
mtechAuthor Commented:
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
 
mehdiCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
mtechAuthor Commented:
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
 
mehdiCommented:
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
 
mtechAuthor Commented:
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
 
mehdiCommented:
Hi

specify your filehandle.

print messtxt "The text I want";
0
 
mtechAuthor Commented:
mehdi

thanks for the help - got it all working ok

mtech
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now