?
Solved

email program

Posted on 1999-11-08
16
Medium Priority
?
152 Views
Last Modified: 2010-03-05
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
0
Comment
Question by:kudak
  • 8
  • 4
  • 2
  • +2
16 Comments
 
LVL 4

Accepted Solution

by:
binkzz earned 100 total points
ID: 2190629
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
 
LVL 4

Expert Comment

by:adam923
ID: 2192272
| is a metacharacter so you need to split on /\|/
0
 

Author Comment

by:kudak
ID: 2192954
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
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
LVL 9

Expert Comment

by:Arunkumar
ID: 2195202
hi

I think the above one will work perfectly
0
 

Author Comment

by:kudak
ID: 2195725
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
 

Author Comment

by:kudak
ID: 2195730
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
 

Author Comment

by:kudak
ID: 2196121
not working yet
0
 
LVL 4

Expert Comment

by:adam923
ID: 2196127
did you even read my comment before? replace /|/ with /\|/
0
 

Author Comment

by:kudak
ID: 2196317
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
 
LVL 85

Expert Comment

by:ozo
ID: 2196338
How many |'s are there in $FORM{'Item'} before the call to &parse_form?
0
 
LVL 4

Expert Comment

by:adam923
ID: 2197636
i agree with ozo, it doesn't seem to make sense to use the %FORM hash before the sub parse_form is called
0
 

Author Comment

by:kudak
ID: 2198872
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
 
LVL 4

Expert Comment

by:adam923
ID: 2198878
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
 

Author Comment

by:kudak
ID: 2198965
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
 

Author Comment

by:kudak
ID: 2198969
ok adam, i'll try
0
 
LVL 85

Expert Comment

by:ozo
ID: 2199688
What does $ENV{QUERY_STRING}; look like?
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question