Solved

Help to modify perl/cgi script

Posted on 2001-06-21
8
326 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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
 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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 shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 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