Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: sendmail working for me but not another

by tobyink (Canon)
on May 25, 2020 at 20:08 UTC ( [id://11117246]=note: print w/replies, xml ) Need Help??


in reply to Re^2: sendmail working for me but not another
in thread sendmail working for me but not another

Also, here's what I mean about eliminating repetition. It's untested though.

#!/usr/bin/perl use strict; use warnings; use CGI qw/:standard/; $CGI::POST_MAX = 1024 * 1; my %fields = ( fstname => [ first => 40 ], lstname => [ last => 40 ], adda => [ 1ad1a => 60 ], addb => [ 1ad1b => 60 ], city => [ 1ad2 => 60 ], state => [ 1ad3 => 20 ], zip => [ 1ad4 => 5 ], email => [ eadd => 70 ], phone => [ pnum => 16 ], residence => [ residence => 9 ], yardtype => [ yardtype => 16 ], yardtypeother => [ yardtypeother => 40 ], landlord => [ landlord => 40 ], preadda => [ 2ad1 => 60 ], precity => [ 2ad2 => 60 ], prestate => [ 2ad3 => 20 ], prezip => [ 2ad4 => 5 ], alone => [ alone => 14 ], household => [ household => 100 ], vet => [ vet => 45 ], pet => [ pet => 3 ], petname => [ petnme => 30 ], currentpets => [ currentpets => 60 ], previouspets => [ previouspets => 60 ], references => [ references => 140 ], ok => [ ok => 7 ], ); my %values; for my $key ( keys %fields ) { my ( $post_param, $max_length ) = @{ $fields{$key} } my $value = substr( param($post_param), 0, $max_length ); $value =~ s/[\|\/\\}{\[\]\(\)\*&\^%\$\#<>;:]/ /g; $values{$key} = $value; } $values{email} =~ tr/[A-Z]/[a-z]/; ## Check email address if ( $values{email} ne "" and $values{email} !~ /\@/ ) { print "Content-type: text/plain\n\n"; print "error (Your email is invalid, please check and resubmit you +r application)"; exit; } ## Check data my $total_form = $values{fstname} . $values{lstname} . $values{email}; if ( length($total_form) < 25 ) { print "Content-type: text/plain\n\n"; print "error (The form was incomplete, please check that you fille +d in your full first and last name, and email address, then resubmit +your application.)"; exit; } my $recipient = "email1\@emailsrv1, email2\@emailsrv2, email3\@emailsr +v3"; ## Create the email message body my $email_message = <<"MESSAGE" To: $values{recipient} Subject: Adoption Application From: $values{fstname} $values{lstname} <$values{email}> First name: $values{fstname} Last name: $values{lstname} Current address: $values{adda} $values{addb} $values{city} $values{state} $values{zip} _________________________________________________ Email address: $values{email} Phone number: $values{phone} Type of residence: $values{residence} Yard: $values{yardtype} Landlord contact info: $values{landlord} Previous address: $values{preadda} $values{precity} $values{prestate} $values{prezip} How many hours will pet be alone: $values{alone} Name and age of people in household: $values{household} Veterinarian: $values{vet} Dog or Cat: $values{pet} Name of pet requested: $values{petname} Current pets: $values{currentpets} Previous pets: $values{previouspets} References: $values{references} Aggree to consent form: $values{ok} MESSAGE ## Send email my $mailprog = '/usr/sbin/sendmail'; open my $mailhandle, '|-' "$mailprog -t" or die "Could not open mailhandle"; print $mailhandle $email_message; close $mailhandle; print "Location: application-submitted\n\n"; exit;

Replies are listed 'Best First'.
Re^4: sendmail working for me but not another
by kickingchicken (Initiate) on May 26, 2020 at 04:15 UTC

    Wow, thanks for this. I see what you mean. I will go through it after I figure out where my error is. In the send mail part

    my $mailprog = '/usr/sbin/sendmail'; open my $mailhandle, '|-' "$mailprog -t" or die "Could not open mailhandle"; print $mailhandle $email_message; close $mailhandle;
    What are you doing with mailhandle?

      For details, see open and fork functions to start.

      That open syntax forks the process (which I had long forgotten); $mailprog is run in child process. A pipe is opened to $mailprog in order to write to its standard input by writing to $mailhandle. (If the pipe-open syntax were -|, then that would be to read standard output of the command.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11117246]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found