Register a domain and help support LQ
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-12-2005, 09:04 AM   #1
Registered: Feb 2005
Posts: 40

Rep: Reputation: 15
Send Mail with Perl

Ok I am running Mandrake 9.1. I wrote a simple program to test sendmail and it does not work. As soon as I reference sendmail I get a 500 server error. Do I need to install a module for perl? I installed already. Please see the program below.

#!/usr/bin/perl -wT
use strict;
use CGI ':standard';
use warnings;

my $test= $ENV{'HTTP_USER_AGENT'};
my $version = $CGI::VERSION;
my $vemail;
my $from="lukeharris_79\";
my $to="lukeharris\";
my $subject="I\'m sending myself a test e-mail!";
my $sendmailpath="/usr/sbin/sendmail";
$vemail= param('vemail');

open (SENDMAIL, "| $sendmailpath -t");
#print SENDMAIL "Subject: $subject\n";
#print SENDMAIL "From: $from\n";
#print SENDMAIL "To: $to\n\n";
#print SENDMAIL "This is a test e-mail.\n\n";
#print SENDMAIL "I like to make lists:\n";
#print SENDMAIL "- One\n";
#print SENDMAIL "- Two\n";
#print SENDMAIL "- Three\n\n";
#print SENDMAIL "Bye!\n\n";
#print SENDMAIL "-Luke Harris";
#close (SENDMAIL);

print "Content-type: text/html\n\n";
print "<html><head></head><body>";
print "<H1>HELLO WORLD!</H1>\n";
print "your viewing this page with $test <br>" ;
print "your email is $vemail <br>";
print "your using version $version<br>";
#print "server admins email is $email<br>";
print "subject is $subject<br>";
print "to is $to<br>";
print "path is $sendmailpath<br>";
print "from is $from<br>";

print "</body></html>";
The program works until I uncomment the sendmail section. I tried uncommentting just the open and the close and sill nothing. It can be noted that the program receives $vemail from a test form and that works.

Oh yeah this is the results of "whereis sendmail" not sure what one to use as my path.

[root@localhost root]# whereis sendmail
sendmail: /usr/sbin/sendmail.postfix /usr/sbin/sendmail /usr/lib/sendmail /usr/share/man/man1/sendmail.1.bz2

Any help is appreciated.


Cool Hand...

Last edited by Cool_Hand_Luke; 03-12-2005 at 09:15 AM.
Old 03-12-2005, 02:44 PM   #2
LQ Newbie
Registered: Mar 2005
Posts: 4

Rep: Reputation: 0
I've had luck with the Net::SMTP module.
Old 03-14-2005, 09:59 AM   #3
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
First things first, since the code uses taint checking, (-T), it will need to define a valid (and untainted) ENV{PATH}. In this case, it could be as simple as:
local $ENV{PATH} = "/usr/sbin";
Second, you've got two ".com"s on the end of the $to definition.

Third, your open to sendmail doesn't do any error checking. It's a very good idea to trap any errors that might occur on the open.

After fixing these issues (of course changing the email addresses to match my own), the code worked just fine.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
perl send mail code pragti Programming 2 03-17-2006 05:48 PM
Perl form wont send mail calmbomb Linux - Software 4 11-07-2004 10:08 AM
Server does'nt send mail until shutdown and LAN can't send or receive. Wolfy Linux - Networking 0 08-02-2004 07:31 PM
howto send a mail with attachment via perl script ? cccc Programming 24 03-05-2004 07:49 PM
I'm looking for a simply perl script to send mail, when ping down cccc Programming 2 01-12-2004 04:36 AM

All times are GMT -5. The time now is 05:06 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration