By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,710 Members | 1,887 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,710 IT Pros & Developers. It's quick & easy.

Issue using Sendmail

jhoborg
P: 6
Hello all,

So I'm having trouble using sendmail in a CGI script as the topic title says.

Here's what I'm trying to accomplish:
User fills out a form, submits it, my CGI script receives this data, emails it to me, then displays a "thank you" html page to the user. Here's a look at the code that calls sendmail:

Expand|Select|Wrap|Line Numbers
  1.     unless (open (MESSAGE,"| /usr/sbin/sendmail -t")){
  2.         die "Can't open sendmail: $!";
  3.         }
  4.     print MESSAGE "To: $email\n" or die $!;
  5.     print MESSAGE "From: $FORM{Coach}\n" or die $!;
  6.     print MESSAGE "Reply-To: $FORM{Email}\n" or die $!;
  7.     print MESSAGE "Subject: Roster from $FORM{School}\n" or die $!;
  8.     print MESSAGE "\n" or die $!;
  9.  
  10.     print MESSAGE "School: $FORM{School}\n" or die $!;
  11.     print MESSAGE "Coach: $FORM{Coach}\n" or die $!;
  12.     print MESSAGE "Invite: $FORM{Invite}\n" or die $!;
  13.     print MESSAGE "Date: $FORM{Date}\n\n" or die $!;    
  14.     print MESSAGE "Roster for $FORM{Category}:\n" or die $!;
  15.  
  16.     close (MESSAGE);
  17.  


Here's what happens:
When my script executes, it displays the html page without error, but I never receive an email. I check my error log and this is what is shown:

[Sat Aug 1 07:08:35 2009 GMT] /path/to/roster.cgi: Use of uninitialized value in concatenation (.) at /full/path/to/Config.pm line 44.
sendmail:


I'm not really sure what, if anything, the first error has to do with what I am doing. Here is the snippet of code in question:
Expand|Select|Wrap|Line Numbers
  1. if ($< == $> and !$CONFIGURE)  {
  2.     my $home = eval { (getpwuid($>))[7] } || $ENV{HOME};
  3.     $file = $home . "/.libnetrc";   ##### line 44 #####
  4.     $ref = eval { do $file } if -f $file;
  5.     %NetConfig = (%NetConfig, %{ $ref })
  6.     if ref($ref) eq 'HASH';    
  7. }
  8.  
It looks like $home is still undefined after line 43, since $ENV{HOME} does not have a value?

The second error, which is simply "sendmail: ", has me a little confused, but I opened up the sendmail program and found where this error might be coming from:

Expand|Select|Wrap|Line Numbers
  1. # Connect to mail server
  2. my $smtp = new My::Net::SMTP "127.0.0.1";
  3. # Make sure it connected
  4. if (!$smtp) {
  5.   if (@{ $My::Net::SMTP::getlines }) {
  6.     # Must have gotten an invalid response
  7.     &failed(5);
  8.   } else {
  9.     # Did not even get a response
  10.     print STDERR "sendmail: $!\n";
  11.   }
  12.   exit ($! || 4);
  13. }
  14.  
And the reason I think the error is a result of this block of code is because of the use of "sendmail: $!\n"

So I guess that means it is not connecting to the mail server? I've tried this CGI script on a different website and it works fine. Not sure what to do next! Please help!
Aug 2 '09 #1
Share this Question
Share on Google+
2 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
@jhoborg
I would say that the first thing to do is overcome that error produced on line 44. I would change it to be the following:

Expand|Select|Wrap|Line Numbers
  1. $file = "${home}/.libnetrc";
  2.  
The reason? Variable interpolation happens inside of double quotes, so no use risking a concatenation error when you can do this. See if it still gives you an error.

Regards,

Jeff
Aug 3 '09 #2

jhoborg
P: 6
Thanks for the reply.

Doesn't look like I have the permissions to edit the file config.pm.. it's in the perl lib, when I try to upload the changed file via FTP it throws a "553 Can't open that file: Permission denied" error.

EDIT: Should I try defining $ENV{HOME} before calling sendmail? I don't know what that would be set to though.
Aug 3 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.