Current location: Hot Scripts Forums » Programming Languages » Perl » HELP -- Perl email form !!


HELP -- Perl email form !!

Reply
  #1 (permalink)  
Old 03-24-04, 02:45 AM
nasos nasos is offline
New Member
 
Join Date: Mar 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy HELP -- Perl email form !!

Hi ,

I am completely new to Perl , I cant even say that I am a newbie Perl programmer !! Ive only used it to make a form in Apache (Cobalt) UNIX Server as previously it worked fine in asp with Windows IIS.
So, I have a form that includes two hidden fields named "subject" and "recipient". There are some other inside the form tha the user can write in. Like the "email" which I want to use as a send_to perl variable.

I am close to solution but....

I have included in the script (searching in the Net) these lines:
<code>my $query = new CGI;
my $HTML_thankyou = 'thankyou.htm';
my $to = 'thanas1@hotmail.com';
my $from = $query->param("Email");
my $mailprog = '/usr/sbin/sendmail';
my $subject = $query->param("subject");
</code>

1) I need to take the from variable from the form field "email" (user's typed) Is that ok?

The next part I included in the script is:

<code>%FORM = parse_cgi();
foreach(@field){$message.="$_: $FORM{$_}\n";}
mymail($to, $from, $subject, $message);
print "Location: $HTML_thankyou\n\n";
exit;

sub parse_cgi{
my %FORM; my $name; my $value; my $content;
my $a=0;
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g if $kill_html_tags;
$value =~ s/<([^>]|\n)*>//g if $kill_html_tags;
if($FORM{$name}){$FORM{$name} = ", ".$value;}
else{$FORM{$name} = $value;}
$field[$a++]=$name;

}
$a=0;
$temp=$ENV{'QUERY_STRING'};
@pairs=split(/&/,$temp);
foreach $item(@pairs) {
($key,$content)= split (/=/,$item,2);
$content =~ tr/+/ /;
$content =~ s/%(..)/pack("c",hex($1))/ge;
$content =~ s/<!--(.|\n)*-->//g if $kill_html_tags;
$content =~ s/<([^>]|\n)*>//g if $kill_html_tags;
if($FORM{$key}){$FORM{$key} .= ", ".$content;}
else{$FORM{$key} = $content;}
$field[$a++]=$key;
}
return %FORM;
}



sub mymail{

open(MAIL,"|$mailprog -t");
print MAIL "To: $_[0]\n";
print MAIL "From: $_[1]\n";
print MAIL "Subject: $_[2]\n\n";
print MAIL "$content\n";
close(MAIL);

</code>

I get an email that has the right Subject, the right sender but I dont have any content inside the email ....
What is wrong with the last part of printing the form's content ???

Im Looking forward to reading your answers !
Reply With Quote
  #2 (permalink)  
Old 04-08-04, 01:21 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
It's a bit late but it still may help you and others:

Code:
#!/usr/bin/perl -w

use strict;
use CGI;
use CGI::Carp qw/fatalsToBrowser/;

my $in = new CGI;

# Config vars
my $sendmail = '/usr/lib/sendmail -t -oi -oem';
my $HTML_thankyou = 'thankyou.htm';

# Message compilation
my $to = 'thanas1@hotmail.com';
my $from = $in->param("Email");
my $subject = $in->param("subject");

# I'd have to see the form to figure out what you are doing here
# and I assume that it has a lot to do with the lack of a message
# body in your e-mails
# foreach(@field){$message.="$_: $FORM{$_}\n";}

# I would put the message body together based on the form fields like so:
my $message = $in->param('message');

# Send the message
open  SENDMAIL, "|$sendmail";
print SENDMAIL "To: $to", $/;
print SENDMAIL "From: $from", $/;
print SENDMAIL "Subject: $subject", $/, $/;  # You need two new lines here
print SENDMAIL "$message", $/;
close SENDMAIL;

# Redirect to thankyou url
print "Location: $HTML_thankyou\n\n";
I also reccomend that you do some data validation on your form inputs before you try to use the values.

~Charlie
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
formmail problem gscraper Perl 12 08-27-04 03:06 AM
notification email when form submitted? jweav Script Requests 1 01-29-04 03:41 PM
How to email form contents elijahmadness Script Requests 2 01-17-04 10:16 AM
Preventing email form abuse LunarOrbit Perl 3 10-04-03 09:55 PM
send email when sending form (asp) bmatth1 Script Requests 0 09-30-03 05:52 AM


All times are GMT -5. The time now is 04:57 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.