CGI/sendmail help

V

Vespasian

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,

<[email protected]@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";
 
P

Paul Lalli

Vespasian said:
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,

<[email protected]@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
 
V

Vespasian

Well this doesn't work either,

use CGI;
use strict;

my $query = new CGI;
my $my_email = '(e-mail address removed)';

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";
 
P

Paul Lalli

Vespasian said:
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 = '(e-mail address removed)';

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
 
V

Vespasian

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
 
C

ced

Paul said:
Define "doesn't work".

Have you read the posting guidelines for this group yet?


...
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,
 
A

axel

Vespasian said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top