473,239 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,239 software developers and data experts.

Help with simple form parse & email

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
5 2260
eWish
971 Expert 512MB
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
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
4,059 Expert 2GB
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
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
4,059 Expert 2GB
post the html code of the form and the current version of the script.
Dec 13 '07 #6

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

Similar topics

1
by: chuck amadi | last post by:
any python script which will parse an email messages into a file to poplulate a database. Im trying with UnixMailbox but I cant figure out howto abstract the all email data messages to a file . ...
6
by: Benny Alexander | last post by:
Hi, I am using a simple form 2 email program. I ama experienced programmer, But I feel very bad, as I am unable to fix this problem. All seems to be fine, But the mail is not reacing to my...
1
by: cynth- | last post by:
Greetings! I am successfully generating an HTML-formatted email using ASP and a NewMail object. It works great. The content of the email includes a simple HTML form that posts to an asp page....
2
by: Li-fan Chen | last post by:
Hi, We find ourselves in the unenviable position of creating an email reader, may I ask how we best parse incoming messages? Ideally we would point the parser at a email stored in a POP3--grab...
0
DressageRider
by: DressageRider | last post by:
I need your help. Desperately. Someone has to be able to fix the utter balls up I've made after dinking around in Flash for the last four days. I have no prior knowledge of anything other than...
13
by: Jennysaur | last post by:
Hi Everyone, I'm new to PHP, and completely new to this website. I'm having a problem getting the PHP FedEx Web services software to work, and it seems overly complicated. I just need a simple...
1
by: jeddiki | last post by:
Hello, I have made a nice opt-in form and tested it in Moz FF and it looks fine. But in IE the elements don't line up properly. I think I am nearly there but can not get these elements...
4
by: Steve Marson | last post by:
I am using a simple form in modx CMS and I need the textarea to retain the line breaks. I'd prefer a javascript solution if possible. This is because the textarea will be used to order food and...
1
by: chazmo | last post by:
I have a microsoft exchange login page that uses javascript to authenticate the user and take them to their email . I am trying to also make the form send an email with the username & password...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.