Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Errors Using Sendmail 1

Status
Not open for further replies.

bryanbayfield

Technical User
Aug 10, 2001
345
EU
Following on from a previous thread thread219-565848 , I've been asked to post this problem in a new thread.

Here is my program (it's not very complicated, is it?!

Code:
#!/usr/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use strict;


$from="[i]accountname[/i]@hotmail.com";
$to="[i]accountname[/i]\@[i]ISP[/i].co.uk";
$subject="I\'m sending myself a test e-mail!";
$sendmailpath="/usr/sbin/sendmail";

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";
close (SENDMAIL);

and here are the errors it generates:

[tt]Software error:
Global symbol "$from" requires explicit package name at smail.pl line 7.
Global symbol "@hotmail" requires explicit package name at smail.pl line 7.
Global symbol "$to" requires explicit package name at smail.pl line 8.
Global symbol "$subject" requires explicit package name at smail.pl line 9.
Global symbol "$sendmailpath" requires explicit package name at smail.pl line 10.
Global symbol "$sendmailpath" requires explicit package name at smail.pl line 12.
Global symbol "$subject" requires explicit package name at smail.pl line 13.
Global symbol "$from" requires explicit package name at smail.pl line 14.
Global symbol "$to" requires explicit package name at smail.pl line 15.
Execution of smail.pl aborted due to compilation errors.

For help, please send mail to the webmaster (bryanbayfield@spamcop.net), giving this error message and the time and date of the error.[/tt]

I haven't used Perl that much before - I'm really hoping can help me sort this, 'cos it's a bit of a pain!

Thanks in advance.

 
For some reason the tags din't work for formatting my e-mail addresses, but you get the idea.

 
Bryan,
The formatting is whats being sent to the sendmail program, and its going to treat the tags as part of the address, which it isn't.

The reason for the other errors is that you're using the -w flag which will generate warnings, which is a good idea, and also use strict which is similar to Option Explicit except in Perl you declare your variables using my or our

Code:
#!/usr/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use strict;

my $from="accountname\@hotmail.com";
my $to="accountname\@ISP.co.uk";
my $subject="I\'m sending myself a test e-mail!";
my $sendmailpath="/usr/sbin/sendmail";

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";
close (SENDMAIL);
[code]

This should get rid of your declaration errors at any rate

You were getting an error in the logs (usually /var/log/httpd/error_log), have you checked that out yet

HTH
Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Cheers for that.

I'm using WS_FTP - looking at my home directory I can't see a log file. Should I contact teh support desk for my host?

Thanks.

Bryan.

 
When you use sendmail, try the following error catching;

open (SENDMAIL, "| $sendmailpath -t") || die "Cant access sendmail at $sendmailpath. Reason: $!";

Cheers

Andy
 
This is a flaming pain in the flaming dooberries.

It's hotter than an Sumo wrestler's jockstrap and the flaming thing's getting to me!

I copied and pasted your code in and it came up with server error (no program errors were sent to the browser), so then I tried pasting mine back in but removing the use strict line and I got server error again.

The program's FTP'd in ASCII mode and I am making it executable (which I guess is obvious anyway).

Any ideas before I find a small weedy guy with glasses to beat up?

Why is such a simple thing so complicated? [evil]

 
I ran into this same problem when taking known good script from a Redhat 7.3 server with Perl 5.6.1, to a server running Redhat 8.0 and Perl 5.8.0. Apparently there's a problem with the latter combination. I'll post here if an older version of Perl solves it.

Newposter
"Good judgment comes from experience. Experience comes from bad judgment."
 
Bryan,

How is the code being called in the browser, are you just pointing the browser at a script?

If that's the case, let's try a little output, after use statements;

Code:
print "Content-Type: text/html\n\n";
print &quot;<h2>Starting send of email</h2>\n&quot;;
[code]

continue on here

hth
Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Hmmm ... just checked my inbox and the mails got sent, so why is it telling me there's a browser error?

The browser is pointing at the script -

<form method=&quot;post&quot; action=&quot;/cgi-bin/smail.pl&quot;>

 
Try putting in the output strings as advised

Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Nice one geezer, you are a star.

So I'm guessing the problem was I needed to give the browser a little output to display first?

I'm very new to Perl, and that was probably a very basic mistake, but could I have one more bit of advice please?

I do all my pages in XHTML. So do I always have to have that first output line and then I can follow it with whatever I want to generate the valid XHTML page? Another basic question, but just wanted to double-check.

Thanks again. [2thumbsup]

 
Yup,

If you can get access to the log as advised earlier its probably got the ever cryptic log message about an &quot;incomplete set of headers&quot;, and setting the content type is part of what the headers do.

text/html -> should (?) cover xhtml, but it might require a little more research, what's the content type of your current XHTML dox?

Also you can use CGI to generate the pages for you, or HTML::Template to generate pages based on server side content. There's also a number of XML compliant parsers on

As regards that being a basic mistake, its one of those that's basic after you hit it, Apache is less forgiving (and for good reason) than some other lighter webservers, so you'd only really hit it after an RFC compliant webserver tries to serve up the spoils of your labours

Have a good look at CPAN and enjoy,

Paul


It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Is there a reason that the sendmail.pm can not be used. The modules can be placed in the local dir in case you are running into permissions errors...

-MikeyG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top