blat email setup.

previuosly i run my script under unic. noe i try under NT. i've got a problem when i try to run my email program.
below is part of the coding.


$mailprog = "c:\blat\blat.exe";    

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

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

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

if ($found_err) {
      &PrintError; }


$recip = "rizam\";
$cc_recip = "sales\";
open (MAIL, "|$mailprog") || die print "Cannot open mailprog";
print MAIL "To: $recip\n\n";
print MAIL "cc: $cc_recip\n";
print MAIL "From: $FORM{'Email'}\n";
print MAIL "Subject: web order\n";
print MAIL "Form Posted From: $ENV{'HTTP_REFERER'}\n";
print MAIL "\n\n";
print MAIL "\n" ;
print MAIL "Username         : ".$FORM{'usr'}."\n";
print MAIL "Password         : ".$FORM{'passw'}."\n";
if ($FORM{'deladdress'})
print MAIL "Delivery Address : ".$FORM{'deladdress'}."\n";
print MAIL "*******************************************************************\n";

print MAIL "\n";

if ($FORM{'Item0'})
print MAIL "hi there \n";
print MAIL "Item Number     : ".$FORM{'Item0'}."\n";
print MAIL "Re. Number      : ".$FORM{'ID0'}."\n";
print MAIL "Description     : ".$FORM{'Description0'}."\n";
print MAIL "Quantity        : ".$FORM{'Qty0'}."\n";
print MAIL "Price Each      : ".$FORM{'PriceEach0'}."\n";
print MAIL "Sub Total       : ".$FORM{'TotalPrice0'}."\n";
print MAIL "\n";
print MAIL ".\n" ;
print MAIL "\n\n";
close (MAIL);
print "Location:\n";
print "Content-Type: text/html\n\n";
and parse_form code after this.

this program runs smoothly under unix. when i try under NT(using blat), error appears .
the error is:
Cannot open mailprog.

someone please help me
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.

Maybe you need to double up the backslashes in your string?

  $mailprog = "c:\\blat\\blat.exe";
Kim RyanIT ConsultantCommented:
Windows will not understand your first line, #! only has meaning on Unix. Try running your program from commnad line with:  perl

Also for sending mail from windows check: 

kudakAuthor Commented:
teraplane, i've tried to change it(first line) but the script could not run. i ask the server administrator and he told me to use the one that i write.

jmcq, i also have tried yours. the script seems to run smoothly without any errors, but the problem is, the script cannot send that email to the address that i've specified, in this case rizam\ and sales\
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

So do I get partial credit for spotting the problem causing your error message?

This line has an extra \n in it. That's terminating your header early.

print MAIL "To: $recip\n\n";

But I suspect you can't expect Blat to parse your message content to extract the header. These two example scripts for Blat, found through the URL given by teraplane, both write the content of the message to a file and specify the header information on the command line. In this respect, Blat appears to not be a plug-for-plug compatible replacement for Sendmail.
kudakAuthor Commented:
ok, make it as simple as possible.
i've changed my coding to look simpler. below is my coding.


$mailprog = "c:\\blat\\blat.exe";    
$recip = $FORM{'Email'};

open (MAIL, "|$mailprog") || die print "cannot open mailprog";
print MAIL "To: $recip\n";
print MAIL "Subject: Terima Kasih\n";
print MAIL "\n\n";
close (MAIL);
print "<html><title>thanks</title><body><h>hi</h></body></html>\n\n";

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;

when i run this program(key in email address from browser), it'll prompt me to download the file( i suspect that i can not use parse_form function
A. You've forgotten to do to whatever you did to the first script to make it so the httpd executes it rather than downloads it.

B. You did not look at the usage examples I pointed you to. If you had, you would not still be opening a pipe to blat.exe.
hi kudak
I belive that you have the email adresses in the script you want to send that mail to..ok
now there is a very simple answer to you problem..
Get the mails in you program( from the form(oranywhere)..DONE
Now in your
Just do this
system("start blat.exe filename -t <to address> -c <ccemailaddys> -b <bccemailaddys>");
This will do all the sending.
of course you can have error messages if blat does not work..(but in my case it works just fine..)

Hope this help
ASK more if needed

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
kudakAuthor Commented:
i've tried yours khacharn but still i could not run it. well, if you don't mind, could you post your script to me. my email address is

actually i just rent a server(remote server). i really do not know how blat is running. but i have one script i got from the internet.
part of the coding is:

exec("c:/windows/blat c:/zbs/temp/mailfile.txt -t i:/web/docs/ \n\n");
open(MAIL, ">c:/WebSite/temp/mailfile.txt");

can someone tell me what's this coding means??
in my case i think i should code like
exec(c:\blat\blat.exe c:\bla\bla\bls -t xxx \n\n");
what's i:/web/dosc/ (xxx) for?? should'nt it be the same for c:/zbs/temp/mailfile.txt -t and c:/WebSite/temp/mailfile.txt??

Well I have been using Visaul Basic with Blat
So possibly the code won't be of much help..
I will explain you the whole concept..
I think that you have the email address yoou want to mail to..RIGHT ?
Now you need a tool to mail to thet Email..Right ?
USE BLAT in your perl script..HOW ???
here it is..
befor using blat you should know its Functionlaity..
i give you a small example..

<pathofblat.exe> textfile.txt(contians the message you want to send) -t <emailaddress> -b  <emailaddresses>

Now in your perlscript
use it like this
system("start pathofblat.exe textfile.txt -t <emailaddress> -b <emailaddress>
If you still don't get it tell me your problem very specifically
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

From novice to tech pro — start learning today.