Variable in "if" statement

Discussion in 'Perl Misc' started by blnukem, Aug 17, 2004.

  1. blnukem

    blnukem Guest

    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
     
    blnukem, Aug 17, 2004
    #1
    1. Advertising

  2. blnukem

    Anno Siegel Guest

    blnukem <> wrote in comp.lang.perl.misc:
    > 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) ) { ...

    > CODE:


    [snipped]

    Anno
     
    Anno Siegel, Aug 17, 2004
    #2
    1. Advertising

  3. blnukem wrote:
    >
    > 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>

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Aug 17, 2004
    #3
  4. blnukem

    JJ Guest

    if($Name ne ""){
    statements;
    }


    Vincent



    "blnukem" <> schreef in bericht
    news:TqmUc.20778$...
    > 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
    >
    >
     
    JJ, Aug 17, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    811
  2. Jay McGavren
    Replies:
    11
    Views:
    1,149
    Alan Krueger
    Jan 16, 2006
  3. tedsuzman
    Replies:
    2
    Views:
    7,099
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  4. Ted
    Replies:
    1
    Views:
    474
    Duncan Booth
    Jul 22, 2004
  5. Froefel
    Replies:
    1
    Views:
    793
    Mark Rae [MVP]
    Jul 4, 2007
Loading...

Share This Page