PDA

View Full Version : Need help with my Form Mail script


Flite
08-03-2004, 08:54 PM
This script is working fine, but it wont pass the 'realname' variable onto my mailing software.

So when I fill out the form, I receive the autoresponder message like I should, but the subject has the default name "Friend" instead of the name I filled out on the Webform ie:

Friend, here is you free report

instead of

Jason, here is your free report

How can I change this script so that it passes on the name variable?

Thanks for any help

-------------
#!/usr/bin/perl
$mail_prog = '/usr/sbin/sendmail' ;

&GetFormInput;

$realname = $field{'realname'} ;
$email = $field{'email'} ;
$subject = $field{'subject'} ;
$recipient = $field{'recipient'} ;
$redirect = $field{'redirect'} ;
$required = $field{'required'} ;

$message = "" ;
$found_err = "" ;

$errmsg = "<p>Please enter a valid email address</p>\n" ;

if (($email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/) || ($email !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z0-9]+)(\]?)$/)) {
$message = $message.$errmsg ;
$found_err = 1 ; }

if ($found_err) {
&PrintError; }


$recip = "course\@sixweekstosuccess.com" ;
$frm_ = "$email" ;
$sbj_ = "course" ;
$hd_ = $recip.$frm_.$sbj ;
if (($hd =~ /(\n|\r)/m) || ($recip =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/) || ($recip !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z0-9]+)(\]?)$/)) {
print "Fatal Error - Invalid email" ;
exit 0;
}

open (MAIL, "|$mail_prog -t");
print MAIL "To: $recip\n";
print MAIL "Reply-to: $frm_\n";
print MAIL "From: $frm_\n";
print MAIL "Subject: $sbj_\n";
print MAIL "\n\n";
print MAIL "".$realname."\n" ;
print MAIL "\n\n";
close (MAIL);
print "Location: http://www.sixweekstosuccess.com\nURI: http://www.sixweekstosuccess.com\n\n" ;

sub PrintError {
print "Content-type: text/html\n\n";
print $message ;
print "<p> Please use your browser's Back button to return to the form. </p>" ;

exit 0 ;
return 1 ;
}
sub GetFormInput {

(*fval) = @_ if @_ ;

local ($buf);
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
}
else {
$buf=$ENV{'QUERY_STRING'};
}
if ($buf eq "") {
return 0 ;
}
else {
@fval=split(/&/,$buf);
foreach $i (0 .. $#fval){
($name,$val)=split (/=/,$fval[$i],2);
$val=~tr/+/ /;
$val=~ s/%(..)/pack("c",hex($1))/ge;
$name=~tr/+/ /;
$name=~ s/%(..)/pack("c",hex($1))/ge;

if (!defined($field{$name})) {
$field{$name}=$val;
}
else {
$field{$name} .= ",$val";

#if you want multi-selects to goto into an array change to:
#$field{$name} .= "\0$val";
}


}
}
return 1;
}

-------------------------------------------------------------------

MattJakel
08-03-2004, 09:27 PM
This script looks fine to me... Can you post your form too?

Matt

ClubCosmic
08-03-2004, 11:50 PM
why does this line have dbl quotes?

print MAIL "".$realname."\n" ;

it seems to be the only one in the script. i realinze the line break but have you tried other ways without the dbl quotes?

i'm not an expert, it's just an idea but it could be a very small syntax error like that.

good luck

MattJakel
08-04-2004, 06:38 AM
I don't see why that would cause a problem... it looks like correct syntax to me (even though you could make that line cleaner by just using

print MAIL "$realname\n";

Matt

ClubCosmic
08-04-2004, 11:41 PM
i thought dbl quotes meant "whatever the field value is goes here". so maybe it was ignoring everything past the 2nd quote mark.

i didn't know "".$ was legal syntax in php.
i'm still learning myself

MattJakel
08-05-2004, 06:38 AM
Well this is Perl... not PHP. I don't know PHP so I don't know if concatenation exists in that language, but it is pretty important so I assume it does. Anyway, in Perl, the . operator concatenates strings (adds them together). So Perl interprets "".$realname."\n" the same as it would "(variable value here)\n" or "$realname\n". And Perl doesn't stop reading the line after the quotes are terminated. It evealuates everything to the right of print MAIL until the semicolon and prints it to the <MAIL> handler.

Anyway, go ahead and post your form for us Flite so that we can help you out! :thumbsup:

Matt