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++; }

In reply to Unexpected 'newline' token breaks sendmail. by hesco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.