Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > CGI/sendmail help

Reply
Thread Tools

CGI/sendmail help

 
 
Vespasian
Guest
Posts: n/a
 
      01-02-2006
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,

<(E-Mail Removed)@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";

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      01-02-2006
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,
>
> <(E-Mail Removed)@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

 
Reply With Quote
 
 
 
 
Vespasian
Guest
Posts: n/a
 
      01-02-2006
Well this doesn't work either,

use CGI;
use strict;

my $query = new CGI;
my $my_email = '(E-Mail 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";





On 2 Jan 2006 01:44:52 -0800, "Paul Lalli" <(E-Mail Removed)> 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,
>>
>> <(E-Mail Removed)@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


 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      01-02-2006
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 = '(E-Mail 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

 
Reply With Quote
 
Vespasian
Guest
Posts: n/a
 
      01-02-2006
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" <(E-Mail Removed)> 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 = '(E-Mail 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


 
Reply With Quote
 
ced@carios2.ca.boeing.com
Guest
Posts: n/a
 
      01-02-2006

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 = '(E-Mail 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.
>
> 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

 
Reply With Quote
 
axel@white-eagle.invalid.uk
Guest
Posts: n/a
 
      01-05-2006
Vespasian <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Help Help Pentax S5i Help needed (Please) The Martian Digital Photography 14 06-20-2008 07:56 AM
HELP - HELP - HELP =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?= ASP .Net 4 03-09-2006 12:46 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 1 07-16-2004 01:12 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 0 07-16-2004 10:00 AM
HELP! HELP! HELP! Opening Web Application Project Error =?Utf-8?B?dHJlbGxvdzQyMg==?= ASP .Net 0 02-20-2004 05:16 PM



Advertisments