I'm having problems with newlines in the code below (which is modified code and not something I wrote new). Bascially, the problem is that there is an administrative tool (which I did not write nor know how it functions) where a user is entering a message into some kind of interface to then be sent to a list of emails. Each email will include the above message, a url, and an individual username and password. The problem is that returns are being entered into the message and they need to be for formatting and such. The problem is that when the database generates the flatfile that this script runs on, the $message field has the newlines in it and so the while loop doesn't work right because it chomps the line before getting all the way through the message, let alone to the other fields. How do I get the entire message field into $message with the newlines intact for sending?
#!/usr/bin/perl $mailprog = '/usr/sbin/sendmail -t'; $admin_email="admin\@email.org"; $subject="Testing the new mass mailer"; $file = "/actapps/suitespot/cgi-bin/sender/returntest3.txt"; $number_sent = 0; open(DATA, "$file") || die "Can't open $file"; # open the file for +reading while($line = <DATA>) { chop $line; ($junk,$email,$message,$survey_url,$login,$password) = split(/\|/, +$line); open (MAIL, "|$mailprog -t") || die "Can't open $mailprog! \n"; print MAIL "Content-type:text/plain\n"; print MAIL "From: $admin_email\n"; print MAIL "To: $email\n"; print MAIL "Subject: $subject\n"; print MAIL "$message\n\n"; print MAIL "URL: $survey_url\n"; print MAIL "Login: $login\n"; print MAIL "Password: $password\n"; close(MAIL); $number_sent++; }
I'm mostly looking for solutions under the assumption that I can't change the data before I get it, but I'll take any suggestions. I'm still new at this fun called perl, hopefully this is something simple and obvious and explains why i couldn't find any help in the scores of books strewn about. TIA. -W

In reply to newlines and sendmail by hmbscully

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.