email program

hi experts.
i've created email program and it works nicely. this is some of the coding.


$recip = 'xxx@hotmail.com' ;

open (MAIL, "|$mailprg");
print MAIL "To: $recip\n";
print MAIL "Reply-to: rizam\n";
print MAIL "From: rizam1\n";
print MAIL "Subject: web order\n";
print MAIL "\n\n";
print MAIL "\n" ;
print MAIL "".$FORM{'CardOwner'}."\n";
print MAIL "".$FORM{'CardNumber'}."\n";
print MAIL "".$FORM{'CardExpDate'}."\n";
print MAIL "".$FORM{'Item'}."\n";
print MAIL "".$FORM{'ID'}."\n";
print MAIL "".$FORM{'Qty'}."\n";
print MAIL "".$FORM{'Description'}."\n";
print MAIL "".$FORM{'PriceEach'}."\n";
print MAIL "\n\n";
print MAIL "Thanks .\n" ;
print MAIL "\n" ;
print MAIL "visit our website http://xxx.xxx.net\n" ;
print MAIL ".\n" ;
print MAIL "\n\n";
close (MAIL);
}

the problem is, it only prints once. how could i do loop so that when user keys in more that one product, the $item, $id and $description will print that addition to xxx@hotmail.com

thanks for your help
kudakAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

binkzzCommented:
You would have to know how your items are seperated in the html code, if you can give us the html page (or a link to) that would help. Say you're delimeter was a pipe (|);

@items = split (/|/, $FORM{'Item'});
@ids   = split (/|/, $FORM{'ID'});
@qtys  = split (/|/, $FORM{'Qty'});
@descriptions   = split (/|/, $FORM{'Description'});
@prices  = split (/|/, $FORM{'PriceEach'});

for ($item=0; $item <= $#items; $item++)
{
  print "$items[$item]\n";
  print "$ids[$item]\n";;
  print "$qtys[$item]\n";;
  print "$descriptions[$item]\n";;
  print "$prices[$item]\n";;
}


I think that should be about what you want. If you give more specific information then I could give a more detailed explanation if you like.

McT
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
adam923Commented:
| is a metacharacter so you need to split on /\|/
0
kudakAuthor Commented:
ok binkz. i've tried yours, but the same problem occurs.

here is part of my html file.document.writeln('<input type=hidden name="Item" value="+NumItems+">');
                  document.writeln('<input type=hidden name="ID" value="'+ID+'">');
                  document.writeln('<input type=hidden name="Description" value="'+Sdesc+'">');
                  document.writeln('<input type=hidden name="Qty" value="'+Qty+'">');
                  document.writeln('<input type=hidden name="PriceEach" value="'+Price+'">');
(i use javascript). this program works(print once if i use my coding above). i've tried yours. the problem is, it does not even read these 5 fields. the other fields are readable and can be displayed in xxx@hotmail.com

in my mail program, i edited it like this:

$recip = 'xxx@hotmail.com' ;

open (MAIL, "|$mailprg");
print MAIL "To: $recip\n";
print MAIL "Reply-to: rizam\n";
print MAIL "From: rizam1\n";
print MAIL "Subject: web order\n";
print MAIL "\n\n";
print MAIL "\n" ;
print MAIL "".$FORM{'CardOwner'}."\n";
print MAIL "".$FORM{'CardNumber'}."\n";
print MAIL "".$FORM{'CardExpDate'}."\n";


for ($item=0; $item <= $#items; $item++)
{
print MAIL "".$items[$item]."\n";
print MAIL "".$ids[$item]."\n";
print MAIL "".$qtys[$item]."\n";
print MAIL "".$descr[$item]."\n";
print MAIL "".$price[$item]."\n";  
}
print MAIL "\n\n";
print MAIL "Thanks .\n" ;
print MAIL "\n" ;
print MAIL "visit our website http://xxx.xxx.net\n" ;
print MAIL ".\n" ;
print MAIL "\n\n";
close (MAIL);
print "Location: http://xxx.xxx.net\n";
print "Content-Type: text/html\n\n";
exit;



0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

ArunkumarCommented:
hi

I think the above one will work perfectly
0
kudakAuthor Commented:
the above program is not working yet.
below is the whole code.#!/usr/bin/perl

    $mailprg = "/usr/sbin/sendmail -t";  
   
    $line1 = $FORM{'Card Owner'};
    $line2 = $FORM{'Card Number'};
    $line3 = $FORM{'Card Exp Date'};
    $line4 = $FORM{'Email'};
@items = split (/|/, $FORM{'Item'});
@ids   = split (/|/, $FORM{'ID'});
@qtys  = split (/|/, $FORM{'Qty'});
@descr = split (/|/, $FORM{'Description'});
@price = split (/|/, $FORM{'PriceEach'});

    #$line5 = $FORM{'Item'};
    #$line6 = $FORM{'ID'};
    #$line7 = $FORM{'Description'};
    #$line8 = $FORM{'Qty'};
    #$line9 = $FORM{'Price Each'};

# Convert < tags to &lt;
  $line1 =~ s/</\&lt;/g;
  $line2 =~ s/</\&lt;/g;
  $line3 =~ s/</\&lt;/g;
  $line4 =~ s/</\&lt;/g;
  #@items =~ s/</\&lt;/g;
  #@ids   =~ s/</\&lt;/g;
  #@qtys  =~ s/</\&lt;/g;
  #@descr =~ s/</\&lt;/g;
  #@price =~ s/</\&lt;/g;

&parse_form;

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


$errmsg = "<p>card owner error</p>\n" ;

if ($FORM{'CardOwner'} eq "")  
{
      $message = $message.$errmsg ;
      $found_err = 1 ; }


$errmsg = "<p>invalid email address</p>\n" ;

if ($FORM{'Email'} !~ /.+\@.+\..+/)
{
      $message = $message.$errmsg ;
      $found_err = 1 ; }


$errmsg = "<p>card number error</p>\n" ;

if   ($FORM{'CardNumber'} eq "")
{
      $message = $message.$errmsg ;
      $found_err = 1 ; }


$errmsg = "<p>Card Exp. Date error</p>\n" ;

if ($FORM{'CardExpDate'} eq "")
{
      $message = $message.$errmsg ;
      $found_err = 1 ; }


if ($found_err) {
      &PrintError; }


else
   {  


$recip = 'kudak@hotmail.com' ;

open (MAIL, "|$mailprg");
print MAIL "To: $recip\n";
print MAIL "Reply-to: rizam\n";
print MAIL "From: rizam1\n";
print MAIL "Subject: web order\n";
print MAIL "\n\n";
print MAIL "\n" ;
print MAIL "".$FORM{'CardOwner'}."\n";
print MAIL "".$FORM{'CardNumber'}."\n";
print MAIL "".$FORM{'CardExpDate'}."\n";

for ($item=0; $item <= $#items; $item++)
{
 
#print MAIL "".$items[$item]."\n";
#print MAIL "".$ids[$item]."\n";
#print MAIL "".$qtys[$item]."\n";
#print MAIL "".$descr[$item]."\n";
#print MAIL "".$price[$item]."\n";  

#print MAIL "".$FORM{'Item'}."\n";
#print MAIL "".$FORM{'ID'}."\n";
#print MAIL "".$FORM{'Qty'}."\n";
#print MAIL "".$FORM{'Description'}."\n";
#print MAIL "".$FORM{'PriceEach'}."\n";

}

print MAIL "\n\n";
print MAIL "Thanks .\n" ;
print MAIL "\n" ;
print MAIL "visit our website http://chukai.virtualave.net\n" ;
print MAIL ".\n" ;
print MAIL "\n\n";
close (MAIL);
print "Location: http://xxx.xxx.net\n";
print "Content-Type: text/html\n\n";
exit;
}

sub PrintError {
print "Content-type: text/html\n\n";
print '<!doctype html public "-//w3c//dtd html 4.0 transitional//en">'."\n" ;
print "<html>\n" ;
print "<head>\n" ;
print '   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">'."\n" ;
print '   <meta name="Author" content="zidane">'."\n" ;
print '   <meta name="GENERATOR" content="Mozilla/4.61 [en] (Win95; I) [Netscape]">'."\n" ;
print "</head>\n" ;
print "<body>\n" ;
print "&nbsp;\n" ;
print "<br>&nbsp;\n" ;
print "<br>&nbsp;\n" ;
print "<center>\n" ;
print '<p><b><blink><font face="Rockwell Extra Bold"><font size=+1>'.$message.'</font></font></blink></b></center>'."\n" ;
print "weeee\n" ;
print "</body>\n" ;
print "</html>\n" ;

exit 0 ;
return 1 ;
}


sub parse_form {

   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
   if (length($buffer) < 5) {
         $buffer = $ENV{QUERY_STRING};
    }
 
  @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;

      $FORM{$name} = $value;
   }
}




0
kudakAuthor Commented:
the above program is not working yet.
below is the whole code.#!/usr/bin/perl

    $mailprg = "/usr/sbin/sendmail -t";    
     
    $line1 = $FORM{'Card Owner'};
    $line2 = $FORM{'Card Number'};
    $line3 = $FORM{'Card Exp Date'};
    $line4 = $FORM{'Email'};
@items = split (/|/, $FORM{'Item'});
@ids   = split (/|/, $FORM{'ID'});
@qtys  = split (/|/, $FORM{'Qty'});
@descr = split (/|/, $FORM{'Description'});
@price = split (/|/, $FORM{'PriceEach'});

    #$line5 = $FORM{'Item'};
    #$line6 = $FORM{'ID'};
    #$line7 = $FORM{'Description'};
    #$line8 = $FORM{'Qty'};
    #$line9 = $FORM{'Price Each'};

# Convert < tags to &lt;
  $line1 =~ s/</\&lt;/g;
  $line2 =~ s/</\&lt;/g;
  $line3 =~ s/</\&lt;/g;
  $line4 =~ s/</\&lt;/g;
  #@items =~ s/</\&lt;/g;
  #@ids   =~ s/</\&lt;/g;
  #@qtys  =~ s/</\&lt;/g;
  #@descr =~ s/</\&lt;/g;
  #@price =~ s/</\&lt;/g;

&parse_form;

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


$errmsg = "<p>card owner error</p>\n" ;

if ($FORM{'CardOwner'} eq "")  
{
$message = $message.$errmsg ;
$found_err = 1 ; }


$errmsg = "<p>invalid email address</p>\n" ;

if ($FORM{'Email'} !~ /.+\@.+\..+/)
{
$message = $message.$errmsg ;
$found_err = 1 ; }


$errmsg = "<p>card number error</p>\n" ;

if   ($FORM{'CardNumber'} eq "")
{
$message = $message.$errmsg ;
$found_err = 1 ; }


$errmsg = "<p>Card Exp. Date error</p>\n" ;

if ($FORM{'CardExpDate'} eq "")
{
$message = $message.$errmsg ;
$found_err = 1 ; }


if ($found_err) {
&PrintError; }


else
   {  


$recip = 'kudak@hotmail.com' ;

open (MAIL, "|$mailprg");
print MAIL "To: $recip\n";
print MAIL "Reply-to: rizam\n";
print MAIL "From: rizam1\n";
print MAIL "Subject: web order\n";
print MAIL "\n\n";
print MAIL "\n" ;
print MAIL "".$FORM{'CardOwner'}."\n";
print MAIL "".$FORM{'CardNumber'}."\n";
print MAIL "".$FORM{'CardExpDate'}."\n";

for ($item=0; $item <= $#items; $item++)
{
 
print MAIL "".$items[$item]."\n";
print MAIL "".$ids[$item]."\n";
print MAIL "".$qtys[$item]."\n";
print MAIL "".$descr[$item]."\n";
print MAIL "".$price[$item]."\n";  

#print MAIL "".$FORM{'Item'}."\n";
#print MAIL "".$FORM{'ID'}."\n";
#print MAIL "".$FORM{'Qty'}."\n";
#print MAIL "".$FORM{'Description'}."\n";
#print MAIL "".$FORM{'PriceEach'}."\n";

}

print MAIL "\n\n";
print MAIL "Thanks .\n" ;
print MAIL "\n" ;
print MAIL "visit our website http://xxx.xxx.net\n" ;
print MAIL ".\n" ;
print MAIL "\n\n";
close (MAIL);
print "Location: http://xxx.xxx.net\n";
print "Content-Type: text/html\n\n";
exit;
}

sub PrintError {
print "Content-type: text/html\n\n";
print '<!doctype html public "-//w3c//dtd html 4.0 transitional//en">'."\n" ;
print "<html>\n" ;
print "<head>\n" ;
print '   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">'."\n" ;
print '   <meta name="Author" content="zidane">'."\n" ;
print '   <meta name="GENERATOR" content="Mozilla/4.61 [en] (Win95; I) [Netscape]">'."\n" ;
print "</head>\n" ;
print "<body>\n" ;
print "&nbsp;\n" ;
print "<br>&nbsp;\n" ;
print "<br>&nbsp;\n" ;
print "<center>\n" ;
print '<p><b><blink><font face="Rockwell Extra Bold"><font size=+1>'.$message.'</font></font></blink></b></center>'."\n" ;
print "weeee\n" ;
print "</body>\n" ;
print "</html>\n" ;

exit 0 ;
return 1 ;
}


sub parse_form {

   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
   if (length($buffer) < 5) {
         $buffer = $ENV{QUERY_STRING};
    }
 
  @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;

      $FORM{$name} = $value;
   }
}




0
kudakAuthor Commented:
not working yet
0
adam923Commented:
did you even read my comment before? replace /|/ with /\|/
0
kudakAuthor Commented:
i've tried it adam923. the result is still the same. it only prints before the for statement and after the curly bracket.
any
0
ozoCommented:
How many |'s are there in $FORM{'Item'} before the call to &parse_form?
0
adam923Commented:
i agree with ozo, it doesn't seem to make sense to use the %FORM hash before the sub parse_form is called
0
kudakAuthor Commented:
it depends on the users. if users key in 9 items, it's going to be 9 items, 9 ids, 9 qty and so on.
0
adam923Commented:
but ozo asked how many were there BEFORE the call to parse_form. why don't you add in a print statement or two and see what the variables acutally hold a certain points in the program?
0
kudakAuthor Commented:
I use your code binkz,for ($item=0; $item<=$#items; $item++)
#foreach $item(@items)

{
print MAIL "Item            :".$items[$item]."\n";
print MAIL "Ref. number     :".$ids[$item]."\n";;
print MAIL "Quantity        :".$qtys[$item]."\n";;
print MAIL "Description     :".$descr[$item]."\n";;
print MAIL "Price           :".$price[$item]."\n";;
}
 
now, it only prints the last item.
let's say user keys in 6 items. it will print the last item and all the last one details(ref. no, qty, description, price

0
kudakAuthor Commented:
ok adam, i'll try
0
ozoCommented:
What does $ENV{QUERY_STRING}; look like?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.