Variable in "if" statement


B

blnukem

Hi all

I have this sub routine for sending email from my web site but it seems to
have a problem that I cant seem to figure out on the line that reads :

if($Name){
print MAIL "$Name: $Value \n";
}

Now I thought that this should only print if $Name has a value, it print all
the time cant figure it out.


CODE:

sub SendMail {

$FORM{'SendersName'} = lc($FORM{'SendersName'});
$FORM{'SendersName'} =~ s/([\w']+)/\u\L$1/g;
$FORM{'SendersEmail'} = lc($FORM{'SendersEmail'});

open (MAIL, "|$MailProg -t") or die("Can't open $MailProg!\n");
print MAIL "From: $FORM{'SendersName'}\n";
print MAIL "To: $Admin \n";
print MAIL "Subject: $FORM{'Subject'}\n";

print MAIL "Senders Name: $FORM{'SendersName'}\n";
print MAIL "Senders E-Mail: $FORM{'SendersEmail'}\n";
print MAIL "Senders Message: $FORM{'Message'}\n";

foreach $Pair (@Pairs) {
($Name, $Value) = split(/=/, $Pair);
$Name =~ tr/+/ /;
$Name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$Value =~ tr/+/ /;
$Value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$Name} = $Value;

next if (($Name eq "SendersEmail")||($Name eq "Subject")||($Name eq
"Message")
||($Name eq "SendersName"));

if($Name){
print MAIL "$Name: $Value \n";
}
}

close (MAIL);

exit;
}


Thanks in advance
Blnukem
 
Ad

Advertisements

A

Anno Siegel

blnukem said:
Hi all

I have this sub routine for sending email from my web site but it seems to
have a problem that I cant seem to figure out on the line that reads :

if($Name){
print MAIL "$Name: $Value \n";
}

Now I thought that this should only print if $Name has a value, it print all
the time cant figure it out.

Why would you think that? $value doesn't appear in the condition, how
is it supposed to know about it?

if ( $Name and $Value ) { ...

or probably

if ( defined( $name) and defined( $value) ) { ...

[snipped]

Anno
 
G

Gunnar Hjalmarsson

blnukem said:
if($Name){
print MAIL "$Name: $Value \n";
}

Now I thought that this should only print if $Name has a value, it
print all the time cant figure it out.

I don't understand what you mean. But I do understand that the code
you posted prints everything as message headers, and allows anybody to
use your script as a relay for sending anything to an unlimited number
of recipients...

Wouldn't it be a good idea to make use of a quality form-to-mail
script/module instead?

<code>
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top