LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 03-12-2005, 09:04 AM   #1
Cool_Hand_Luke
Member
 
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 CGI.pm already. Please see the program below.

Quote:
#!/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\@msn.com";
my $to="lukeharris\@msn.com.com";
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 CGI.pm 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.

Quote:
[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.

Thanks,

Cool Hand...

Last edited by Cool_Hand_Luke; 03-12-2005 at 09:15 AM.
 
Old 03-12-2005, 02:44 PM   #2
saldkj
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
TheLinuxDuck
Member
 
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:
Code:
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.
 
  


Reply


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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:18 AM.

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