sending an email with cgi

I want to send an email using cgi (written in perl). I get the following error message: "Bad header=Recipient names must be specif:"

Here's the simple sub routine I wrote to send the email:

sub sendEmail {
     ($myEmail, $myMsg) = @_;
     $mailprog= "/usr/sbin/sendmail";
     $recipient= "$myEmail";    
     $body = "This is the email message. $myMsg";
         
     open (MAIL, "|$mailprog") || die "Couldn't open the mail program: $!";
     print MAIL     "To: $recipient\n";
     print MAIL     "Subject: $subject\n";
     print MAIL     "$body\n";
     close MAIL;
}

It's called like this: &sendEmail($email, $msg);

What am I doing wrong? Any help will be appreciated. Thanks.
Jason
hgajasAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
antonsigurConnect With a Mentor Commented:
$mailprog = '/usr/sbin/sendmail';
$recipient = 'name@somewhere.com;

open (MAIL, "|$mailprog -t") or dienice("Can't access $mailprog!\n");

print MAIL "To: $recipient\n";
#print MAIL "Reply-to: $recipient\n";
print MAIL "subject: Form Data\n\n";

print 'The body text';

close(MAIL);


This is working for mee....
0
 
antonsigurCommented:
You forgot the double \n\n

in print MAIL "subject: Form Data\n\n"; If that matters...
0
 
antonsigurCommented:
This is the error :
  $recipient= "$myEmail";

remove the "'s

Or better, replace $myEmail with $recipient
0
 
hgajasAuthor Commented:
Thanks for all three of the quick responses.
0
All Courses

From novice to tech pro — start learning today.