Problems with Sendmail

P

Phantom_guitarist

I am currently having problems creating a script to send an email from perl.
I have got the script down to the bare minimum;

#!/usr/bin/perl
print "Content-type:text/html\n\n";
&mail('(e-mail address removed)','(e-mail address removed)','Test
Message','Test Message');
print "<br>Mail Sent";

sub mail
{
print "Preparing to send<br>";
# first param is recipient
# second is from
# third is subject
# fourth is message
$mailprog = '/usr/sbin/sendmail';
$recipient = $_[0];
$from = $_[1];
$subject = $_[2];
$message = $_[3];
print "To: $recipient\n<br>";
print "From: $from\n<br>";
print "Subject: $subject\n\n<br>";
print $message;
print "<br>";

open(MAIL,'|$mailprog')|| &error("Cant locate mail program");
print MAIL "To: $recipient\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
print MAIL $message;
close (MAIL);
}
sub error
{
print "Content-type:text/html\n\n";
print $_[0];
exit;


but for some reason this doesn't work. It doesn't display any messages and
the script runs fine. I have contact the domain hosting I am with
(http://www.kthosting.com) and they couldn't give me any reason why the
script doesn't work. They have a FromMail.cgi script on their site and that
seems to work ok on sending to my address. If any one knows of any issues
that I am maybe overlooking your help would be very much appreciated.


Stefan
 
G

Gunnar Hjalmarsson

Phantom_guitarist said:
If any one knows of any issues that I am maybe overlooking your
help would be very much appreciated.

open(MAIL,'|$mailprog -t')|| &error("Cant locate mail program");
-------------------------^^^
 
A

Andras Malatinszky

Phantom_guitarist said:
I am currently having problems creating a script to send an email from perl.
I have got the script down to the bare minimum;

#!/usr/bin/perl
print "Content-type:text/html\n\n";
&mail('(e-mail address removed)','(e-mail address removed)','Test
Message','Test Message');
print "<br>Mail Sent";

sub mail
{
print "Preparing to send<br>";
# first param is recipient
# second is from
# third is subject
# fourth is message
$mailprog = '/usr/sbin/sendmail';
$recipient = $_[0];
$from = $_[1];
$subject = $_[2];
$message = $_[3];
print "To: $recipient\n<br>";
print "From: $from\n<br>";
print "Subject: $subject\n\n<br>";
print $message;
print "<br>";

open(MAIL,'|$mailprog')|| &error("Cant locate mail program");

Here you are trying to send stuff to a program called $mailprog in the
directory your script is running in. You probably meant to put that in
double quotes.


print MAIL "To: $recipient\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
print MAIL $message;
close (MAIL);
}
sub error
{
print "Content-type:text/html\n\n";
print $_[0];
exit;

Well, "error" is a fitting name for a script that produces a syntax
error. You need to close that curly.
but for some reason this doesn't work. It doesn't display any messages and
the script runs fine.

I find this difficult to believe...

[snip]
 
B

Brad Baxter

open(MAIL,'|$mailprog -t')|| &error("Cant locate mail program");
-------------------------^^^

Also:

open(MAIL,"|$mailprog -t")|| &error("Cant locate mail program");

Regards,

Brad
 
G

Gunnar Hjalmarsson

Brad said:
Also:

open(MAIL,"|$mailprog -t")|| &error("Cant locate mail program");

Yes, I overlooked that there was single quotes instead of double
quotes. Thanks for pointing it out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top