dark314 has asked for the wisdom of the Perl Monks concerning the following question:

#UPDATE: So theres a variable I use in the second email,
it comes from user input, in a form. Somehow its screwing up
sendmail, but im unsure if its caused by just whitespace,
I tried formatting the string using

$string =~ s/\s+$//;

@@ Thing is, I tried this earlier to no avail... but with this webserver my 
company is using .. I wouldn't be suprised it wasn't working..
eh.. thanks ALOT Perlbotics @@ EndUpdate
So I have a script sending an email with info, it then sends a confirmation email. the first email works fine:
print MAIL <<EOF; Mime-Version: 1.0 Content-type: text/html; charset="iso-8859-1" To: info\.someone\@somecompany.com bcc: $recipient From: info\@somecompany.com Subject: BLABLABLA - $SomeVar - $Date #some text bla bla EOF close(MAIL);
the second part is what bugs me, its pretty much the same
print SECONDMAIL <<EOF; Mime-Version: 1.0 Content-type: text/html; charset="iso-8859-1" To: info\.someone\@somecompany.com bcc: $recipient From: info\@somecompany.com Subject: BLABLABLA - $SomeVar - $Date #some text bla bla EOF close(SECONDMAIL);
so the problem is this, the first email comes through ok, the second email comes through, but does not retail the bcc:, from:, or even the subject:!!!, instead, bcc,from, and subject are included in the email as text inside the email, as oppose to information sendmail uses. (it just copies the rest of the text directly as the message) what could I possibly be doing wrong?

Replies are listed 'Best First'.
Re: using sendmail with perl, second email does not recognize anything but To:
by Perlbotics (Archbishop) on Nov 23, 2008 at 13:29 UTC

    Just a guess: Header and body of an eMail are separated by an empty line. A (CR)/LF might have been sneaked into one of your variables. You should substitute each occurrence of \n \r or \x0a \x0c \x0d from your header-$variables before the template is evaluated.

Re: using sendmail with perl, second email does not recognize anything but To:
by eye (Chaplain) on Nov 23, 2008 at 19:32 UTC
    If a line terminator in $string is the source of your problems, your regex will not correct it. I believe you need to force the substitution to treat the string as a single line and then replace the characters that are potential problems. In some scenarios, it might be better to replace runs of line terminators with a space, though that will depend on context. Also, it would be better to assume that there may be more than one line terminator. Example:
    #!/usr/bin/perl $string = "foo bar"; $string =~ s/\s+$//; print $string, "\n\n"; $string =~ s/[\r\n]+/ /gs; print $string, "\n\n";
    This produces:
    foo bar foo bar
    NOTE: It is always dangerous to directly insert user input in a mail header; user input warrants careful scrutiny. The documentation on tainting in the perlsec reference is very helpful on this subject.
Re: using sendmail with perl, second email does not recognize anything but To:
by fmerges (Chaplain) on Nov 23, 2008 at 20:52 UTC