newbie: unusual email output

Discussion in 'Perl' started by Duke of Hazard, Jan 21, 2004.

  1. I have this code:
    -----------------

    print MAIL "Comments if any:\n";
    print MAIL "================\n\n";
    print MAIL "$x_comments";
    print MAIL "\n\n";

    close (MAIL);

    Which produces this unexpected output when x_comments is null
    -------------------------------------------------------------

    Comments if any:
    ================



    omments if any:
    ================


    Any idea why it is printing it twice?

    Thanks,

    Faraz
     
    Duke of Hazard, Jan 21, 2004
    #1
    1. Advertising

  2. Duke of Hazard wrote:
    > I have this code:
    > -----------------
    >
    > print MAIL "Comments if any:\n";
    > print MAIL "================\n\n";
    > print MAIL "$x_comments";
    > print MAIL "\n\n";
    >
    > close (MAIL);
    >
    > Which produces this unexpected output when x_comments is null


    What null? The text November-Uniform-Lima-Lima?
    The number 0?
    A binary value of \0x00?

    > -------------------------------------------------------------
    >
    > Comments if any:
    > ================
    >
    >
    >
    > omments if any:
    > ================
    >
    >
    > Any idea why it is printing it twice?


    Well, the code you are showing to us won't print anything but an error
    message about MAIL not being opened. What is your real code?

    (Hint: your problem probably has nothing to do with those print statements
    but with some 'interesting' logic in your program).

    jue
     
    Jürgen Exner, Jan 22, 2004
    #2
    1. Advertising

  3. Here's the code pasted below. Everything works as it should, except
    the last line seems to get printed twice.

    ###################################################
    # mailing faraz_hussainyahoo.com cc'ing $x_email1 #
    ###################################################

    $mail_prog = '/usr/sbin/sendmail -t' ;


    if ($x_email1) {

    open (MAIL, "|$mail_prog");
    print MAIL "From: $r0\n";
    print MAIL "To: $r0,$r1,$r2,$r3\n";
    print MAIL "Cc: $x_email1\n";
    print MAIL "Subject: ISRA - New member\n";
    print MAIL "The following person has joined ISRA\n";
    print MAIL "====================================\n\n";
    print MAIL "$x_lastname, $x_firstname\n\n";

    print MAIL "DOB, sex\n";
    print MAIL "==========\n\n";
    print MAIL "$x_dob, $x_sex\n\n";

    print MAIL "Address 1\n";
    print MAIL "==========\n\n";
    print MAIL "$x_address1 \n $address2\n";

    print MAIL "City, state and zip:\n";
    print MAIL "====================\n\n";
    print MAIL "$x_city ,$x_state ,$x_zip \n\n";

    print MAIL "Home, work and cellphone\n";
    print MAIL "========================\n\n";
    print MAIL "$x_homephone , $x_workphone ,$x_cellphone \n\n";

    print MAIL "With the following rating:\n";
    print MAIL "==============================\n\n";
    print MAIL "$x_rating\n\n";
    print MAIL "The following contact information was provided:\n";
    print MAIL "===============================================\n\n";
    print MAIL "$x_email1, $x_email2\n\n";

    print MAIL "Volunteer?\n";
    print MAIL "==========\n\n";
    print MAIL "$x_volunteer\n\n";

    print MAIL "Comments if any:\n";
    print MAIL "================\n\n";
    print MAIL "$x_comments";
    print MAIL "\n\n";

    close (MAIL);
    } # end of if statement

    ##################################################################
    ##################################################################
     
    Duke of Hazard, Jan 22, 2004
    #3
  4. Duke of Hazard

    Brad Olin Guest

    On 22 Jan 2004 07:03:34 -0800, (Duke of Hazard)
    wrote:

    Your script is similar to a script I have. I think you could use a some
    error management, an easer style, and a tip on email headers.

    >Here's the code pasted below. Everything works as it should, except
    >the last line seems to get printed twice.
    >
    >###################################################
    ># mailing faraz_hussainyahoo.com cc'ing $x_email1 #
    >###################################################
    >
    >$mail_prog = '/usr/sbin/sendmail -t' ;
    >
    >
    >if ($x_email1) {
    >
    >open (MAIL, "|$mail_prog");


    If this open fails, which happens, then your script will fail and you
    won't know it. Try this...

    open MAIL, "|/usr/sbin/sendmail -t" or die "Can't open sendmail: $!\n";

    You then go through each line with it's own print statement, nothing
    wrong with this, but it is easer to follow/maintain/format if you...

    print MAIL <<eof;
    From: $r0
    To: $r0,$r1,$r2,$r3
    Cc: $x_email1
    Subject: ISRA - New member

    The following person has joined ISRA
    ====================================
    <insert the rest of the body here>
    eof
    close MAIL or die "Can't close sendmail: $!/$?\n";
    } # end of if

    >print MAIL "From: $r0\n";
    >print MAIL "To: $r0,$r1,$r2,$r3\n";
    >print MAIL "Cc: $x_email1\n";
    >print MAIL "Subject: ISRA - New member\n";
    >print MAIL "The following person has joined ISRA\n";



    Here I want to point out that there MUST be a blank line between the
    last header and the body of the email. This may seem like I'm picking a
    nit, but it's not really me... every email related program requires it
    as the separator between header and body. This may well be what is
    causing the problem you are looking for.



    Brad
    --
    "He who asks is a fool for five minutes, but he who does not ask remains
    a fool forever." Chinese proverb

    Bradley W. Olin http://www.bwo1.com
     
    Brad Olin, Jan 22, 2004
    #4
  5. Duke of Hazard

    Guest

    (Duke of Hazard) wrote in message news:<>...
    > Here's the code pasted below. Everything works as it should, except
    > the last line seems to get printed twice.


    [snip incomplete code]

    Well, the code you are showing to us won't do anything because it's
    all wrapped in an if with a condition that'll be undefined.

    What is your real code?

    (Hint: your problem probably has nothing to do with those print
    statements but with some 'interesting' logic in your program).

    Deja vu?

    (Further hint: Got any forks?)

    Please see the posting guidelines that are posted frequently in
    comp.lang.perl.misc for advice on how to ask questions effectively in
    technical newsgroups.

    This newsgroup does not exist (see FAQ). Please do not start threads
    here.
     
    , Jan 23, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William A. Sempf

    Unusual performance problem.

    William A. Sempf, Aug 27, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    377
    William A. Sempf
    Aug 27, 2003
  2. Farooq Khan
    Replies:
    3
    Views:
    435
    Jim Cheshire [MSFT]
    Oct 24, 2003
  3. Marty McDonald

    SoapException - unusual behavior

    Marty McDonald, May 17, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    682
    Marty McDonald
    May 19, 2004
  4. thomson
    Replies:
    1
    Views:
    397
    =?Utf-8?B?aG4=?=
    Nov 19, 2004
  5. Mav
    Replies:
    22
    Views:
    371
Loading...

Share This Page