For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > June 2005 > Send Mail Issue









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Send Mail Issue
Anish Kumar K

2005-06-04, 8:55 am

This is the program I am using for SENDMAIL. Surprisingly it is not dying.
I could see an error message in the browser as "The System cannot find the path specified". I donno from where the message is coming..

I removed the sendmail part and then checked, now the error is not coming....I am sure it is with the sendmail. Is it some thing to do with the sendmail.

Any other module which will accomplisj the task....



#!/usr/local/bin/perl
use strict;
use warnings;
use CGI;

my $cgi=new CGI;
print $cgi->header();
my $name = &clean($cgi->param('name')); // THIS IS FROM THE html FILE
my $age = &clean($cgi->param('age')); // THIS IS FROM THE html FILE

my $sendmail = "/usr/sbin/sendmail -t";
my $reply_to = "Reply-to: anish\@tst.com";
my $subject = "Subject: Confirmation of your submission";
my $content = "Thanks for your submission.";
my $to = "anish\@tess.com";

unless ($to) {
print $cgi->header;
print "Please fill in your email and try again";
}

open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
print sendmail $reply_to;
print sendmail $subject;
print sendmail $to;
print sendmail "Content-type: text/plain\n\n";
print sendmail $name;
print sendmail $description;
close(SENDMAIL);

print $cgi->header;
print "Confirmation of your submission will be emailed to you.";

sub clean
{
# Clean up any leading and trailing whitespace
# using regular expressions.
my $s = shift @_;
$s =~ s/^\s+//;
$s =~ s/\s+$//;
return $s;
}



John Doe

2005-06-04, 8:55 am

Am Samstag, 4. Juni 2005 08.38 schrieb Anish Kumar K:
> This is the program I am using for SENDMAIL. Surprisingly it is not dying.


It even does not compile.

> I could see an error message in the browser as "The System cannot find the
> path specified". I donno from where the message is coming..
> I removed the sendmail part and then checked, now the error is not
> coming....I am sure it is with the sendmail. Is it some thing to do with
> the sendmail.
>
> Any other module which will accomplisj the task....


For example (code snippet)

use Mail::Send;

my $msg = new Mail::Send ( Subject=>$subject, To=>$email ) or die $!;

#$msg->set('Reply-To', $Reply_to);
$msg->set('Bcc', $Bcc);
$msg->set('From', $From);

# The filehandle returned is an instance of the Mail::Mailer class.
my $fh = $msg->open;
print $fh <<EOF;
Mail body
EOF
$fh->close or die; # complete the message and send it

see search.cpan.org for the Mail::Send Module.


> #!/usr/local/bin/perl
> use strict;
> use warnings;
> use CGI;
>
> my $cgi=new CGI;
> print $cgi->header();
> my $name = &clean($cgi->param('name')); // THIS IS FROM THE html FILE
> my $age = &clean($cgi->param('age')); // THIS IS FROM THE html FILE


$name and $age could be better sanitized: age should only contain numbers, and
name not all chars, no line breaks etc.

Also try to set a default value to avoid warnings about undefined variables:

my $age=$cgi->param('age') || '0'; # or whatever
# TODO: sanitize

"//" is not the way to comment in perl, gives syntax error.

> my $sendmail = "/usr/sbin/sendmail -t";
> my $reply_to = "Reply-to: anish\@tst.com";
> my $subject = "Subject: Confirmation of your submission";
> my $content = "Thanks for your submission.";
> my $to = "anish\@tess.com";
>
> unless ($to) {
> print $cgi->header;


The header has already been printed above.

> print "Please fill in your email and try again";


After that, the program continues...

> }
>
> open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
> print sendmail $reply_to;
> print sendmail $subject;
> print sendmail $to;
> print sendmail "Content-type: text/plain\n\n";
> print sendmail $name;
> print sendmail $description;


$description is not defined.

> close(SENDMAIL);


This could fail.

> print $cgi->header;


The header is printed the 3rd time?!?

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


Not sure. The sending could have failed.

> sub clean
> {
> # Clean up any leading and trailing whitespace
> # using regular expressions.
> my $s = shift @_;
> $s =~ s/^\s+//;
> $s =~ s/\s+$//;
> return $s;
> }



joe
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com