By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,722 Members | 1,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,722 IT Pros & Developers. It's quick & easy.

Help with simple form parse & email

P: 3
Hi im totally new to perl this is my first go at using it (I normally use asp).
I have set up a form with a cgi script from demon hosting. I have edited the script and the form works it sends me an email. however all the information is missing form the email I only get the first form text field??
Expand|Select|Wrap|Line Numbers
  1. #!/bin/perl 
  2.  
  3.  
  4.  
  5.  
  6.  
  7. # ------------------------------------------------------------
  8.  
  9. # Form-mail.pl, by Reuven M. Lerner (reuven@the-tech.mit.edu).
  10.  
  11. #
  12.  
  13. # Last updated: March 14, 1994
  14.  
  15. #
  16.  
  17. # Form-mail provides a mechanism by which users of a World-
  18.  
  19. # Wide Web browser may submit comments to the webmasters
  20.  
  21. # (or anyone else) at a site.  It should be compatible with
  22.  
  23. # any CGI-compatible HTTP server.
  24.  
  25.  
  26. # Please read the README file that came with this distribution
  27.  
  28. # for further details.
  29.  
  30. # ------------------------------------------------------------
  31.  
  32.  
  33.  
  34. # ------------------------------------------------------------
  35.  
  36. # This package is Copyright 1994 by The Tech. 
  37.  
  38.  
  39.  
  40. # Form-mail is free software; you can redistribute it and/or modify it
  41.  
  42. # under the terms of the GNU General Public License as published by the
  43.  
  44. # Free Software Foundation; either version 2, or (at your option) any
  45.  
  46. # later version.
  47.  
  48.  
  49.  
  50. # Form-mail is distributed in the hope that it will be useful, but
  51.  
  52. # WITHOUT ANY WARRANTY; without even the implied warranty of
  53.  
  54. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  55.  
  56. # General Public License for more details.
  57.  
  58.  
  59.  
  60. # You should have received a copy of the GNU General Public License
  61.  
  62. # along with Form-mail; see the file COPYING.  If not, write to the Free
  63.  
  64. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  65.  
  66. # ------------------------------------------------------------
  67.  
  68.  
  69.  
  70. # Define fairly-constants
  71.  
  72.  
  73.  
  74. # This should be set to the username or alias that runs your WWW server.
  75.  
  76. $recipient = 'sales@mywebsite.co.uk';
  77.  
  78.  
  79.  
  80. # This should be set to the URL of your home page, or wherever
  81.  
  82. # you wish users to return.
  83.  
  84. $homepage = 'http://www.mywebsite.co.uk';
  85.  
  86.  
  87.  
  88. # This should match the mail program on your system.
  89.  
  90. $mailprog = '/usr/lib/sendmail';
  91.  
  92.  
  93.  
  94. # Print out a content-type for HTTP/1.0 compatibility
  95.  
  96. print "Content-type: text/html\n\n";
  97.  
  98.  
  99.  
  100. # Print a title and initial heading
  101.  
  102. print "<Head><Title>Thank you</Title></Head>";
  103.  
  104. print "<Body><H1>Thank you</H1>";
  105.  
  106.  
  107.  
  108. # Get the input
  109.  
  110. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  111.  
  112.  
  113.  
  114. # Split the name-value pairs
  115.  
  116. @pairs = split(/&/, $buffer);
  117.  
  118.  
  119.  
  120. foreach $pair (@pairs)
  121.  
  122. {
  123.  
  124.     ($name, $value) = split(/=/, $pair);
  125.  
  126.  
  127.  
  128.     # Un-Webify plus signs and %-encoding
  129.  
  130.     $value =~ tr/+/ /;
  131.  
  132.     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  133.  
  134.  
  135.  
  136.     # Stop people from using subshells to execute commands
  137.  
  138.     # Not a big deal when using sendmail, but very important
  139.  
  140.     # when using UCB mail (aka mailx).
  141.  
  142.     # $value =~ s/~!/ ~!/g; 
  143.  
  144.  
  145.  
  146.     # Uncomment for debugging purposes
  147.  
  148.     # print "Setting $name to $value<P>";
  149.  
  150.     $FORM{$name} = $value;
  151.  
  152. }
  153.  
  154.  
  155.  
  156. # If the comments are blank, then give a "blank form" response
  157.  
  158. #&blank_response unless $FORM{'FirstName'};
  159.  
  160. #&blank_response unless $FORM{'LastName'};
  161.  
  162. #&blank_response unless $FORM{'StreetAddress'};
  163.  
  164. #&blank_response unless $FORM{'City'};
  165.  
  166. #&blank_response unless $FORM{'County'};
  167.  
  168. #&blank_response unless $FORM{'PostCode'};
  169.  
  170. #&blank_response unless $FORM{'WorkPhoneNumber'};
  171.  
  172. #&blank_response unless $FORM{'Email'};
  173.  
  174.  
  175.  
  176. # Now send mail to $recipient
  177.  
  178.  
  179.  
  180. open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
  181.  
  182. print MAIL "Reply-to: $FORM{'Email'} ($FORM{'LastName'})\n";
  183.  
  184. print MAIL "Subject: mywebsite trade account applications (Forms submission)\n\n";
  185.  
  186. print MAIL "$FORM{'FirstName'} ($FORM{'LastName'}) sent the following\n";
  187.  
  188. print MAIL "mywebsite trade account application for \n\n";
  189.  
  190. print MAIL  "------------------------------------------------------------\n";
  191.  
  192. print MAIL "$FORM{'FirstName'}";
  193.  
  194. print MAIL "$FORM{'LastName'}";
  195.  
  196. print MAIL "$FORM{'StreetAddress'}";
  197.  
  198. print MAIL "$FORM{'Address2'}";
  199.  
  200. print MAIL "$FORM{'City'}";
  201.  
  202. print MAIL "$FORM{'County'}";
  203.  
  204. print MAIL "$FORM{'PostCode'}";
  205.  
  206. print MAIL "$FORM{'WorkPhoneNumber'}";
  207.  
  208. print MAIL "$FORM{'HomePhoneNumber'}";
  209.  
  210. print MAIL "$FORM{'FAX'}";
  211.  
  212. print MAIL "$FORM{'Email'}";
  213.  
  214. print MAIL "$FORM{'CashOrCredit'}";
  215.  
  216. print MAIL "$FORM{'Ref1_Company'}";
  217.  
  218. print MAIL "$FORM{'Ref1_StreetAddress'}";
  219.  
  220. print MAIL "$FORM{'Ref1_Address'}";
  221.  
  222. print MAIL "$FORM{'Ref1_City'}";
  223.  
  224. print MAIL "$FORM{'Ref1__County'}";
  225.  
  226. print MAIL "$FORM{'Ref1_PostCode'}";
  227.  
  228. print MAIL "$FORM{'Ref1_PhoneNumber'}";
  229.  
  230. print MAIL "$FORM{'Ref1_FAX'}";
  231.  
  232. print MAIL "$FORM{'Ref1_Email'}";
  233.  
  234. print MAIL "$FORM{'Ref2_Company'}";
  235.  
  236. print MAIL "$FORM{'Ref2_StreetAddress'}";
  237.  
  238. print MAIL "$FORM{'Ref2_Address'}";
  239.  
  240. print MAIL "$FORM{'Ref2_City'}";
  241.  
  242. print MAIL "$FORM{'Ref2__County'}";
  243.  
  244. print MAIL "$FORM{'Ref2_PostCode'}";
  245.  
  246. print MAIL "$FORM{'Ref2_PhoneNumber'}";
  247.  
  248. print MAIL "$FORM{'Ref2_FAX'}";
  249.  
  250. print MAIL "$FORM{'Ref2_Email'}";
  251.  
  252. print MAIL "\n------------------------------------------------------------\n";
  253.  
  254. print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n";
  255.  
  256. #print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
  257.  
  258. print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
  259.  
  260. close (MAIL);
  261.  
  262.  
  263.  
  264. # Make the person feel good for writing to us
  265.  
  266. print "Thank you for your request, your e-mail is on its way to our Flimwell Office<P>";
  267.  
  268. print "Return to our <A HREF='http://www.mywebsite.co.uk'>home page</A>, if you want.<P>";
  269.  
  270.  
  271.  
  272. # ------------------------------------------------------------
  273.  
  274. # subroutine blank_response
  275.  
  276. sub blank_response
  277.  
  278. {
  279.  
  280.     print "Your comments appear to be blank, and thus were not sent ";
  281.  
  282.     print "to our webmasters.  Please re-enter your comments, or ";
  283.  
  284.     print "return to our <A HREF='http://www.mywebsite.co.uk'>home page</A>, if you want.<P>";
  285.  
  286.     exit;
  287.  
  288. }
  289.  
  290.  
the email works but returns :-

simon

LastName () sent the following
mywebsite trade account application for

------------------------------------------------------------
simon

LastName
------------------------------------------------------------
Server protocol: HTTP/1.1
Remote IP address: 83.104.77.213



i know its a simple out dated script but i cant see what is wrong with it???
Dec 12 '07 #1
Share this Question
Share on Google+
5 Replies


eWish
Expert 100+
P: 971
Add the following lines of code, fix the errors and then see if it will work for you.

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. # If you are executing this script from the bwoser add this line too.
  5. use CGI::Carp qw/fatalsToBrowser/;
--Kevin
Dec 12 '07 #2

P: 3
if i add that code i get a 500 error

i have debugged the script i get:-

Redirecting STDERR to STDOUT
Query_String: ''
Path_Info: '<NULL>'
Remote Host: '<NULL>'
Remote Addr: '83.104.77.213'

Results of stat:
File Owner: '45708'
File Group: '999'

User Data Retrieved:
UserName: 'webadmi1'
UID: '45708'
GID: '999'
Directory: '/home/webadmi1'
Sanitize script name: 'xx-form-mail.pl'
Sanitized to: 'xx-form-mail.pl'
Sanitize path name: '/cgi-bin/www.tate-fencing.co.uk/xx-form-mail.pl'
sanitized to: '/cgi-bin/www.tate-fencing.co.uk/xx-form-mail.pl'

Log Request
Opening log file.
Writing log entry.
Closing log file.
Done logging request.

UIDs/GIDs Changed To:
RUID: '45708'
EUID: '45708'
RGID: '999'
EGID: '999'


Output of script follows:
================================================== ===
path: '/cgi-bin/www.tate-fencing.co.uk/xx-form-mail.pl'
argv[0]: 'xx-form-mail.pl'
argv[1]: '<NULL>'
Content-type: text/html

<Head><Title>Thank you</Title></Head><Body><H1>Thank you</H1>Your comments appear to be blank, and thus were not sent to our webmasters. Please re-enter your comments, or return to our <A HREF='http://www.tate-fencing.co.uk'>home page</A>, if you want.<P>
Dec 12 '07 #3

KevinADC
Expert 2.5K+
P: 4,059
Did you get it working? From looking at the code I can't see why it would not send all the form data in the email.
Dec 13 '07 #4

P: 3
Did you get it working? From looking at the code I can't see why it would not send all the form data in the email.
No im still scratching my head, ???? ive no idea why it misses out fields??

ive tried re-naming my input boxes - it doesnt change?
ive tried cutting bits out of the print mail ?

it seems to only find the first field (shows the right data) then prints the neame of the second input box not the data in it!!?!?!?!?!

ahhhhhhhh!
Dec 13 '07 #5

KevinADC
Expert 2.5K+
P: 4,059
post the html code of the form and the current version of the script.
Dec 13 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.