CGI/sendmail help

Discussion in 'Perl Misc' started by Vespasian, Jan 2, 2006.

  1. Vespasian

    Vespasian Guest

    The first open MAIL always sends an email. The second does not. If
    fact, I got a failure notice from the second one with the following
    error,

    <@host428.ipowerweb.com>:
    Sorry, no mailbox here by that name. (#5.1.1)

    It seems the the second MAIL wants to append '@host428.ipowerweb.com'
    Maybe not

    Any ideas?
    ves


    # Code
    use CGI;

    my $query = new CGI;
    my $content = "Thanks for your submission.\r\n";
    my $email = $query->param('send_to');
    $email =~ s/\@/\\\@/;

    my $from = "From: ss.net 1\n";
    my $to = "To: $email\n";
    my $subject = "Subject: Reservation request\n\n";

    my $sendmail = "/usr/sbin/sendmail -t -f \'$email\'";
    my $file = "logfile.txt";


    #open (LOG, ">>$file") or print "Cannot open $file: $!";
    #print LOG $to,"\n";
    #close(LOG);

    print "Content-type: text/html\n\n";
    print $sendmail,"<br>";
    print $from;
    print $to;
    print $subject;

    $|=1;
    if (1) {
    open (MAIL, "| /usr/sbin/sendmail -t -f
    \'keepitsimple222\@yahoo.com\'") || print "Opening sendmail failed:
    $!";
    print MAIL "From: tester\@1testdomain.com\r\n";
    print MAIL "To: keepitsimple222\@yahoo.com\r\n";
    print MAIL "Subject: old code 6\r\n";
    print MAIL "Hi there. This script sure works great on UNIX, doesn't
    it?\r\n";
    close (MAIL);
    }

    if(1) {
    open(MAIL, "| $sendmail") || print "Opening sendmail failed: $!";
    print MAIL $from;
    print MAIL $to;
    print MAIL $subject;
    print MAIL $content;
    close (MAIL);
    }

    print "Confirmation of your submission will be emailed to you.\n";
    Vespasian, Jan 2, 2006
    #1
    1. Advertising

  2. Vespasian

    Paul Lalli Guest

    Vespasian wrote:
    > The first open MAIL always sends an email. The second does not. If
    > fact, I got a failure notice from the second one with the following
    > error,
    >
    > <@host428.ipowerweb.com>:
    > Sorry, no mailbox here by that name. (#5.1.1)
    >
    > It seems the the second MAIL wants to append '@host428.ipowerweb.com'
    > Maybe not
    >
    > # Code
    > use CGI;


    You have forgotten
    use strict;
    use warnings;

    > my $query = new CGI;
    > my $content = "Thanks for your submission.\r\n";
    > my $email = $query->param('send_to');
    > $email =~ s/\@/\\\@/;


    Here is your problem. What makes you think you want to do this? @
    have to be escaped in double-quoted string literals. They should not
    be escaped within a scalar variable. Remove this line.

    > my $from = "From: ss.net 1\n";
    > my $to = "To: $email\n";
    > my $subject = "Subject: Reservation request\n\n";


    One other thing, that I don't know whether or not it's causing a
    problem. Here, you're using \n for your line endings. . .

    > print MAIL "From: tester\@1testdomain.com\r\n";
    > print MAIL "To: keepitsimple222\@yahoo.com\r\n";
    > print MAIL "Subject: old code 6\r\n";


    But here, you're using \r\n. Why the difference?

    > #open (LOG, ">>$file") or print "Cannot open $file: $!";
    > #print LOG $to,"\n";
    > #close(LOG);


    Please do not post commented-out code. It does nothing but clutter
    your post.

    > print "Content-type: text/html\n\n";
    > print $sendmail,"<br>";
    > print $from;
    > print $to;
    > print $subject;
    >
    > $|=1;
    > if (1) {
    > open (MAIL, "| /usr/sbin/sendmail -t -f
    > \'keepitsimple222\@yahoo.com\'") || print "Opening sendmail failed: $!";


    If you had assigned this string to a variable, and printed it out, you
    would see that the string that gets sent to sendmail contains only a @,
    not a \@. Compare and contrast with the output you printed earlier.

    Paul Lalli
    Paul Lalli, Jan 2, 2006
    #2
    1. Advertising

  3. Vespasian

    Vespasian Guest

    Well this doesn't work either,

    use CGI;
    use strict;

    my $query = new CGI;
    my $my_email = '';

    print "Content-type: text/html\n\n";
    print $my_email,"<br>";

    $|=1;
    if (1) {
    open (MAIL, "| /usr/sbin/sendmail -t -f
    \'keepitsimple222\@yahoo.com\'") || print "Opening sendmail failed:
    $!";
    print MAIL "From: surftama\@surftamarindo.net\n";
    print MAIL "To: keepitsimple222\@yahoo.com\n";
    print MAIL "Subject: old code 12\n\n";
    print MAIL "Hi there. This script sure works great on UNIX, doesn't
    it?\r\n";
    close (MAIL);
    }


    if(1) {
    open (MAIL, "| /usr/sbin/sendmail -t -f \'$my_email\'") || print
    "Opening sendmail failed: $!";
    print MAIL "From: surftama\@surftamarindo.net\n";
    print MAIL "To: $my_email\n";
    print MAIL "Subject: new code 12\n\n";
    print MAIL "Hi there. This script sure works great on UNIX, doesn't
    it?\r\n";
    close (MAIL);
    }



    print "Confirmation of your submission will be emailed to you.\n";





    On 2 Jan 2006 01:44:52 -0800, "Paul Lalli" <> wrote:

    >Vespasian wrote:
    >> The first open MAIL always sends an email. The second does not. If
    >> fact, I got a failure notice from the second one with the following
    >> error,
    >>
    >> <@host428.ipowerweb.com>:
    >> Sorry, no mailbox here by that name. (#5.1.1)
    >>
    >> It seems the the second MAIL wants to append '@host428.ipowerweb.com'
    >> Maybe not
    >>
    >> # Code
    >> use CGI;

    >
    >You have forgotten
    >use strict;
    >use warnings;
    >
    >> my $query = new CGI;
    >> my $content = "Thanks for your submission.\r\n";
    >> my $email = $query->param('send_to');
    >> $email =~ s/\@/\\\@/;

    >
    >Here is your problem. What makes you think you want to do this? @
    >have to be escaped in double-quoted string literals. They should not
    >be escaped within a scalar variable. Remove this line.
    >
    >> my $from = "From: ss.net 1\n";
    >> my $to = "To: $email\n";
    >> my $subject = "Subject: Reservation request\n\n";

    >
    >One other thing, that I don't know whether or not it's causing a
    >problem. Here, you're using \n for your line endings. . .
    >
    >> print MAIL "From: tester\@1testdomain.com\r\n";
    >> print MAIL "To: keepitsimple222\@yahoo.com\r\n";
    >> print MAIL "Subject: old code 6\r\n";

    >
    >But here, you're using \r\n. Why the difference?
    >
    >> #open (LOG, ">>$file") or print "Cannot open $file: $!";
    >> #print LOG $to,"\n";
    >> #close(LOG);

    >
    >Please do not post commented-out code. It does nothing but clutter
    >your post.
    >
    >> print "Content-type: text/html\n\n";
    >> print $sendmail,"<br>";
    >> print $from;
    >> print $to;
    >> print $subject;
    >>
    >> $|=1;
    >> if (1) {
    >> open (MAIL, "| /usr/sbin/sendmail -t -f
    >> \'keepitsimple222\@yahoo.com\'") || print "Opening sendmail failed: $!";

    >
    >If you had assigned this string to a variable, and printed it out, you
    >would see that the string that gets sent to sendmail contains only a @,
    >not a \@. Compare and contrast with the output you printed earlier.
    >
    >Paul Lalli
    Vespasian, Jan 2, 2006
    #3
  4. Vespasian

    Paul Lalli Guest

    Vespasian wrote:
    > Well this doesn't work either,


    Define "doesn't work".

    Have you read the posting guidelines for this group yet?

    >
    > use CGI;
    > use strict;
    >
    > my $query = new CGI;
    > my $my_email = '';
    >
    > print "Content-type: text/html\n\n";
    > print $my_email,"<br>";
    >
    > $|=1;
    > if (1) {
    > open (MAIL, "| /usr/sbin/sendmail -t -f
    > \'keepitsimple222\@yahoo.com\'") || print "Opening sendmail failed:
    > $!";


    Do you actually have three lines here? Or is that a line-wrapping
    error? If this line is three lines, put it back into one.

    > print MAIL "From: surftama\@surftamarindo.net\n";
    > print MAIL "To: keepitsimple222\@yahoo.com\n";
    > print MAIL "Subject: old code 12\n\n";
    > print MAIL "Hi there. This script sure works great on UNIX, doesn't
    > it?\r\n";
    > close (MAIL);
    > }
    >
    >
    > if(1) {
    > open (MAIL, "| /usr/sbin/sendmail -t -f \'$my_email\'") || print
    > "Opening sendmail failed: $!";
    > print MAIL "From: surftama\@surftamarindo.net\n";
    > print MAIL "To: $my_email\n";
    > print MAIL "Subject: new code 12\n\n";
    > print MAIL "Hi there. This script sure works great on UNIX, doesn't
    > it?\r\n";
    > close (MAIL);
    > }
    >
    > print "Confirmation of your submission will be emailed to you.\n";


    Once the lines were fixed so that the -f option to sendmail doesn't
    have a newline after it, the script works fine for me. Two emails
    sent.

    Paul Lalli
    Paul Lalli, Jan 2, 2006
    #4
  5. Vespasian

    Vespasian Guest

    It's a line-wrapping error. THe sendmail is one line. Doesn't work
    means it did not send an email, while the other one did.

    ves

    On 2 Jan 2006 14:04:29 -0800, "Paul Lalli" <> wrote:

    >Vespasian wrote:
    >> Well this doesn't work either,

    >
    >Define "doesn't work".
    >
    >Have you read the posting guidelines for this group yet?
    >
    >>
    >> use CGI;
    >> use strict;
    >>
    >> my $query = new CGI;
    >> my $my_email = '';
    >>
    >> print "Content-type: text/html\n\n";
    >> print $my_email,"<br>";
    >>
    >> $|=1;
    >> if (1) {
    >> open (MAIL, "| /usr/sbin/sendmail -t -f
    >> \'keepitsimple222\@yahoo.com\'") || print "Opening sendmail failed:
    >> $!";

    >
    >Do you actually have three lines here? Or is that a line-wrapping
    >error? If this line is three lines, put it back into one.
    >
    >> print MAIL "From: surftama\@surftamarindo.net\n";
    >> print MAIL "To: keepitsimple222\@yahoo.com\n";
    >> print MAIL "Subject: old code 12\n\n";
    >> print MAIL "Hi there. This script sure works great on UNIX, doesn't
    >> it?\r\n";
    >> close (MAIL);
    >> }
    >>
    >>
    >> if(1) {
    >> open (MAIL, "| /usr/sbin/sendmail -t -f \'$my_email\'") || print
    >> "Opening sendmail failed: $!";
    >> print MAIL "From: surftama\@surftamarindo.net\n";
    >> print MAIL "To: $my_email\n";
    >> print MAIL "Subject: new code 12\n\n";
    >> print MAIL "Hi there. This script sure works great on UNIX, doesn't
    >> it?\r\n";
    >> close (MAIL);
    >> }
    >>
    >> print "Confirmation of your submission will be emailed to you.\n";

    >
    >Once the lines were fixed so that the -f option to sendmail doesn't
    >have a newline after it, the script works fine for me. Two emails
    >sent.
    >
    >Paul Lalli
    Vespasian, Jan 2, 2006
    #5
  6. Vespasian

    Guest

    Paul Lalli wrote:
    > Vespasian wrote:
    > > Well this doesn't work either,

    >
    > Define "doesn't work".
    >
    > Have you read the posting guidelines for this group yet?
    >
    > >
    > > use CGI;
    > > use strict;
    > >
    > > my $query = new CGI;
    > > my $my_email = '';
    > >
    > > print "Content-type: text/html\n\n";
    > > print $my_email,"<br>";
    > >
    > > $|=1;
    > > if (1) {
    > > open (MAIL, "| /usr/sbin/sendmail -t -f
    > > \'keepitsimple222\@yahoo.com\'") || print "Opening sendmail failed:
    > > $!";

    >
    > ...
    > Do you actually have three lines here? Or is that a line-wrapping
    > error? If this line is three lines, put it back into one.
    >
    > Once the lines were fixed so that the -f option to sendmail doesn't
    > have a newline after it, the script works fine for me. Two emails
    > sent.
    >


    To the OP:

    In this case, seeing the problem was a bit tricky because of the pipe
    and absence of an error check after the close(MAIL).
    See: perldoc -f close

    At least during debugging, you could add the following to catch
    potential problems:

    use CGI::Carp qw/fatalsToBrowser/;
    ...
    close( MAIL ) or die "mail error: $! : $?";

    Many of the mail modules though, eg., Mail::Mailer, could help you
    avoid
    these problems and be more portable as well.

    hth,
    --
    Charles DeRykus
    , Jan 2, 2006
    #6
  7. Vespasian

    Guest

    Vespasian <> wrote:
    > The first open MAIL always sends an email. The second does not. If
    > fact, I got a failure notice from the second one with the following
    > error,


    [code snipped]

    Others have answered your question.

    > if (1) {
    > open (MAIL, "| /usr/sbin/sendmail -t -f
    > \'keepitsimple222\@yahoo.com\'") || print "Opening sendmail failed:
    > $!";
    > print MAIL "From: tester\@1testdomain.com\r\n";
    > print MAIL "To: keepitsimple222\@yahoo.com\r\n";
    > print MAIL "Subject: old code 6\r\n";
    > print MAIL "Hi there. This script sure works great on UNIX, doesn't
    > it?\r\n";
    > close (MAIL);
    > }


    Why when opening sendmail fails, do you continue
    to attemt to print to it?

    Axel
    , Jan 5, 2006
    #7
    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. sugapablo
    Replies:
    0
    Views:
    2,141
    sugapablo
    Sep 21, 2007
  2. Andrzej Adam Filip
    Replies:
    0
    Views:
    4,060
    Andrzej Adam Filip
    Mar 31, 2008
  3. Ninou
    Replies:
    0
    Views:
    174
    Ninou
    Mar 4, 2004
  4. john.swilting

    problems cgi and sendmail

    john.swilting, Jan 21, 2007, in forum: Perl Misc
    Replies:
    4
    Views:
    173
    Martin Ki├čner
    Jan 21, 2007
  5. sstark
    Replies:
    1
    Views:
    90
    sstark
    May 30, 2007
Loading...

Share This Page