How to send email using perl
Alexander Surbakti
alex at indo.com
Mon Jan 3 23:16:37 EST 2005
I try to search in google and I found this script with some of modify:
#!/usr/bin/perl
use CGI;
$send_to = param('send_to');
if ($send_to eq '') {
<FORM method="POST" action="?">
<INPUT type="text" name="send_to">
<INPUT type="submit">
</FORM>
}
else {
my $query = new CGI;
my $sendmail = "/usr/sbin/sendmail -t";
my $reply_to = "Reply-to: alex at indo.com";
my $subject = "Subject: Confirmation of your submission";
my $content = "Thanks for your submission.";
my $to = $query->param('send_to');
my $file = "subscribers.txt";
unless ($to) {
print $query->header;
print "Please fill in your email and try again";
}
open (FILE, ">>$file") or die "Cannot open $file: $!";
print $to,"\n";
close(FILE);
my $send_to = "To: ".$query->param('send_to');
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
print SENDMAIL $reply_to;
print SENDMAIL $subject;
print SENDMAIL $to;
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL $content;
close(SENDMAIL);
print $query->header;
print "Confirmation of your submission will be emailed to you.";
}
The script I named with sendingmail.pl. When I run the script it just
print $to which is the email address I typed in form before submited
and no email come in $to inbox.
As an addition, my perl script put in different server with our mail
server. sendingmail.pl I put in cgi-bin at training.indo.com while our
mail server is mail.indo.com. My question is what should I do with
$sendmail? It seems that the path is belongs to sendmail in mail server.
thanks,
-alex-
More information about the summaries
mailing list