I'm getting errors which look like this, trying to run the code below. My question is, where does this 'newline' get introduced and what can I do about it that I haven't already done?
-- Hugh
Update
Thanks folks. I'm starting to toy around the edges with refactoring some code I wrote years ago and stretched and prodded at for a long time. Its been installed on three or five servers so far that I am aware of. You're seeing small pieces of it. This routine was pulled from a cgi script and has just been dropped into a module with a proper ->new() constructor. My $self = { }; above was simply an adaptation to create something runnable.
Thanks VSarkiss. That was helpful.
My error messages and a runnable snippet follows.
[Fri Oct 13 07:32:42 2006] [error] [client 192.168.1.102] sh: -c: line
+ 1: syntax error near unexpected token `newline'
[Fri Oct 13 07:32:42 2006] [error] [client 192.168.1.102] sh: -c: line
+ 1: `/usr/sbin/sendmail -f script-cgi@tld.hostname.com him@thatone.ex
+ample.net,her@theotherone.example.net "Coordinator's Name" <test@mydo
+main.com>'
[Fri Oct 13 07:32:42 2006] [error] [client 192.168.1.102] Now sending
+email using the `sendmail` method.
And the code I'm working with should run as this:
#!/usr/bin/perl -w
use strict;
use Mail::Mailer;
my $self = {};
my $from = "script-cgi\@tld.hostname.com";
my $to = "him\@thatone.example.net,her\@theotherone.example.net";
my $cc = "\"Coordinator's Name\" <test\@mydomain.com>";
my $subject = "Test sendemail path";
my $email_method = "sendmail";
my $msg =<<EOM;
This is a test message.
This is only a test.
EOM
&sendemail($self,$from,$to,$cc,$subject,$msg,$email_method);
1;
sub sendemail() {
my($self,$from,$to,$cc,$subject,$msg,$email_method)=@_;
my($hdr,$qmail,$sendmail);
chomp($from); chomp($to); chomp($cc);
$qmail = "/var/qm/bin/qmail-inject";
$sendmail = "/usr/sbin/sendmail -f $from $to $cc";
if($email_method eq "qmail"){
# code similiar to the next case
} elsif ($email_method eq "sendmail") {
$hdr =<<EOH;
From: $from
To: $to
Cc: $cc
Subject: $subject
EOH
open (MAILER, "|$sendmail" ) || die "Unable to open sendmail";
print MAILER ( $hdr, $msg );
close MAILER;
print STDERR "Now sending email using the `sendmail` method.";
return 1;
} elsif ($email_method eq "mailer") {
my $mailer = Mail::Mailer->new();
$mailer->open({ From => "$from",
To => "$to",
Cc => "$cc",
Subject => "$subject",
})
or die "Can not open: $! \n";
print $mailer $msg;
$mailer->close();
return 1;
} else {
return 0;
}
} # END sendemail()
if( $lal && $lol ) { $life++; }