cwebber1 has asked for the wisdom of the Perl Monks concerning the following question:

I have a perl script which is working on most email servers, but my client has a gmail address and it is converting the text email to an non openable attachment on chrome, what needs to be changed? script attached 2 part. I am no expert just dangerous enough to get it to work. It works fine on safari. Part one
#!/usr/local/bin/perl #### # # Program: question1.pl # Cimmaron Design # 702 448-4927 # #### #### # # Image Uploading Routine # #### #### # # The libraries to use... CGI for the CGI functions used in print sta +tements. # Use 'perldoc CGI' to find out more about the CGI functions. # #### use CGI qw/:all/; #### # # Begin of the main code # #### #### # # The param function will determine if there was a CGI submission. # #### if (param) { #### # # This is where we want to be, print out a nice HTML header # and start to process the stuff that the server will send in # email to the user and the guys who are going to actually # fill the order. # #### print STDOUT header; print STDOUT start_html('View Sovereign Questionnaire'); #### # # Okay - next we will verify *all* the fields on the order # form are listed properly, and verify their correctness. # If those conditions are met, then we'll print out what the # email will look like, and save it off to a variable that we # can pipe to the email program. # #### $your_email_address = param('your_email_address'); $your_name = param('your_name'); $email_subject_line = param('email_subject_line'); $required_fields = param('required_fields'); $thank_you_title = param('thank_you_title'); $return_link_url = param('return_link_url'); $return_link_name = param('return_link_name'); $client_email = param('client_email'); $client_name = param('client_name'); $client_phone = param('client_phone'); $tell = param('tell'); $owned = param('owned'); $lookingfor = param('lookingfor'); $how = param('how'); $fenced = param('fenced'); $time = param('time'); $sex = param('sex'); $house = param('house'); $out = param('out'); $comp = param('comp'); $comments = param('comments'); #### # # Now - to verify each of the *required* entries... the # undefined ones weren't used in what the user listed... # We'll go through all the errors, and then print out what # we find, instead of breaking if there's just one and not # showing any others we might find as well, to make it more # usable. # #### $err_no = 0; if ( ! defined($your_email_address) ) { $err[$err_no++]="Invalid hidden fields 'your_email_address'\n" +; } if ( ! defined($your_name) ) { $err[$err_no++]="Invalid hidden fields 'your_name'\n"; } if ( ! defined($email_subject_line) ) { $err[$err_no++]="Invalid hidden fields 'email_subject_line'\n" +; } if ( ! defined($thank_you_title) ) { $err[$err_no++]="Invalid hidden fields 'thank_you_title'\n"; } if ( ! defined($return_link_url) ) { $err[$err_no++]="Invalid hidden fields 'return_link_url'\n"; } if ( ! defined($return_link_name) ) { $err[$err_no++]="Invalid hidden fields 'return_link_name'\n"; } #### # # User information next... # #### if ( ! defined($client_email) ) { $err[$err_no++]="You must enter an email address\n"; } else { if ( $client_email eq "" ) { $err[$err_no++]="You must enter an email address\n"; } } if ( ! defined($client_name) ) { $err[$err_no++]="You must enter a name\n"; } else { if ( $client_name eq "" ) { $err[$err_no++]="You must enter a name\n"; } } if ( ! defined($client_phone) ) { $err[$err_no++]="You must enter a phone number\n"; } else { if ( $client_name eq "" ) { $err[$err_no++]="You must enter a phone number\n"; } } #### # # Verifications complete. Next we check if there were # any errors. If there were, print them, and exit, if not, # then print out what we're here after - the order form. # #### if ( $err_no > 0 ) { print STDOUT h2({-align=>'center'}, font( {-color=>"#AF0000"}, "Submitted Questionnaire - Sovereign +Brittanys - errors" ) ), "\n"; print STDOUT hr( {-noshade} ), "\n"; print STDOUT "<UL>\n"; for ( $i = 0 ; $i < $err_no; $i++ ) { print STDOUT li($err[$i]), "\n"; } print STDOUT "</UL>\n"; print STDOUT end_html, "\n"; exit; } #### # # So - lets print out some HTML to show them what they ordered, # and get verification that it's all good. # #### print STDOUT h2({-align=>'center'}, font( {-color=>"#AF0000"}, "Submitted Sovereign Questionnaire" ) ), +"\n"; print STDOUT hr( {-noshade} ), "\n"; print STDOUT "<pre>\n"; if ($imageError) { my @vars = sort(keys(%ENV)); #foreach(@vars) { # $ENV{$_} ||= qq~›~; #print qq~ # # $of\$ENV{$_}$cf # $of$ENV{$_}$cf # #~; #} print STDOUT " Upload Error: $returned\n"; } print STDOUT "Email Address: $client_email\n"; print STDOUT "Your Name: $client_name\n"; print STDOUT "Your Phone: $client_phone\n"; print STDOUT "____________________________________________________ +_______________________\n"; if ( length($tell) > 1 ) { print STDOUT "Please tell us a little about your home and fami +ly (including number of children and ages at home). \n"; print STDOUT "$tell\n"; print STDOUT "____________________________________________________ +_______________________\n"; } if ( length($owned) > 1 ) { print STDOUT "Have you owned a dog/Brittany (raised a puppy)? +\n"; print STDOUT "$owned\n"; print STDOUT "____________________________________________________ +_______________________\n"; } if ( length($lookingfor) > 1 ) { print STDOUT "What are you looking for in a Brittany? \n"; print STDOUT "$lookingfor\n"; print STDOUT "____________________________________________________ +_______________________\n"; } if ( length($how) > 1 ) { print STDOUT "If you are looking for a hunting dog, how often +do you hunt? Will you be using a professional trainer? \n"; print STDOUT "$how\n"; print STDOUT "____________________________________________________ +_______________________\n"; } if ( length($fenced) > 1 ) { print STDOUT "Do you have a fenced in yard? \n"; print STDOUT "$fenced\n"; print STDOUT "____________________________________________________ +_______________________\n"; } if ( length($sex) > 1 ) { print STDOUT "Are you looking for a male or female, or open to + either? \n"; print STDOUT "$sex\n"; print STDOUT "____________________________________________________ +_______________________\n"; } if ( length($house) > 1 ) { print STDOUT "Where will this puppy/dog live? Where will it st +ay when you are not home? \n"; print STDOUT "$house\n"; print STDOUT "____________________________________________________ +_______________________\n"; } if ( length($out) > 1 ) { print STDOUT "Will there be someone home during the day to tak +e the puppy out? \n"; print STDOUT "$out\n"; print STDOUT "____________________________________________________ +_______________________\n"; } if ( length($comp) > 1 ) { print STDOUT "Do you have any interest in competing with your +dog (ie. conformation shows, hunt tests, field trials, agility, obedience, rally, lure coursing, barn hunt, etc)? \n"; print STDOUT "$comp\n"; print STDOUT "____________________________________________________ +_______________________\n"; } if ( length($comments) > 1 ) { print STDOUT "Additional Comments:\n"; print STDOUT "$comments\n"; } print STDOUT "</pre>\n"; print STDOUT "<form action=\"question2.pl\" method=\"POST\">\n"; ##### # # Now, for the next cgi in line, we'll need ALL # the elements of the last page, to print out on the # email that's going to the address specified in the # html file, and the one specified on the form (the client) # #### if (!$imageError) { print STDOUT "<input type=\"hidden\" name=\"upload_name\" valu +e=\"$returned\">\n"; print STDOUT "<input type=\"hidden\" name=\"upload_type\" valu +e=\"$fileType\">\n"; } print STDOUT "<input type=\"hidden\" name=\"your_email_address\" v +alue=\"$your_email_address\">\n"; print STDOUT "<input type=\"hidden\" name=\"your_name\" value=\"$y +our_name\">\n"; print STDOUT "<input type=\"hidden\" name=\"email_subject_line\" v +alue=\"$email_subject_line\">\n"; print STDOUT "<input type=\"hidden\" name=\"required_fields\" valu +e=\"$required_fields\">\n"; print STDOUT "<input type=\"hidden\" name=\"thank_you_title\" valu +e=\"$thank_you_title\">\n"; print STDOUT "<input type=\"hidden\" name=\"return_link_url\" valu +e=\"$return_link_url\">\n"; print STDOUT "<input type=\"hidden\" name=\"return_link_name\" val +ue=\"$return_link_name\">\n"; print STDOUT "<input type=\"hidden\" name=\"client_email\" value=\ +"$client_email\">\n"; print STDOUT "<input type=\"hidden\" name=\"client_name\" value=\" +$client_name\">\n"; print STDOUT "<input type=\"hidden\" name=\"client_phone\" value=\ +"$client_phone\">\n"; print STDOUT "<input type=\"hidden\" name=\"client_phone\" value=\ +"$client_phone\">\n"; print STDOUT "<input type=\"hidden\" name=\"tell\" value=\"$tell\" +>\n"; print STDOUT "<input type=\"hidden\" name=\"owned\" value=\"$owned +\">\n"; print STDOUT "<input type=\"hidden\" name=\"lookingfor\" value=\"$ +lookingfor\">\n"; print STDOUT "<input type=\"hidden\" name=\"how\" value=\"$how\">\ +n"; print STDOUT "<input type=\"hidden\" name=\"fenced\" value=\"$fenc +ed\">\n"; print STDOUT "<input type=\"hidden\" name=\"time\" value=\"$time\" +>\n"; print STDOUT "<input type=\"hidden\" name=\"sex\" value=\"$sex\">\ +n"; print STDOUT "<input type=\"hidden\" name=\"house\" value=\"$house +\">\n"; print STDOUT "<input type=\"hidden\" name=\"out\" value=\"$out\">\ +n"; print STDOUT "<input type=\"hidden\" name=\"comp\" value=\"$comp\" +>\n"; print STDOUT "<input type=\"hidden\" name=\"comments\" value=\"$co +mments\">\n"; print STDOUT "<hr><div align=\"center\">\n"; print STDOUT "<input type=\"submit\" name=\"submit\" value=\"OK\"> +\n"; print STDOUT "<input type=\"button\" name=\"back\" value=\"Back\" +onclick=\"history.back()\">\n"; print STDOUT "</div>\n"; } else { #### # # Somehow they got here without going to the order form html # page... so lets just print out an error and tell them to hit # a link to the submissionform.html page # #### print STDOUT header; print STDOUT start_html('Error'); print STDOUT h1( {-align=>'center'}, font( {-color=>'#AF0000'}, "Error") ), "\n"; print STDOUT hr( {-noshade} ), "\n"; print STDOUT div( {-align=>'center'}, "Please return to the ", a({-href=>'questionnaire18.html'}, "Questionnaire") , "\n", "instead of calling this CGI directly\n"), "\n"; } #### # # That's all folks :-) # #### print STDOUT end_html, "\n";
Part 2
#!/usr/local/bin/perl #### # # Program: svetime2.pl # Cimmaron Design 7/2017 # 720 448-4927 # #### #### # # The libraries to use... CGI for the CGI functions used in print sta +tements. # Use 'perldoc CGI' to find out more about the CGI functions. # #### use CGI qw/:all/; #### # # The param function will determine if there was a CGI submission. # #### if (param) { #### # # This is where we want to be, print out a nice HTML header # and start to process the stuff that the server will send in # email to the user and the guys who are going to actually # fill the inquiry . # #### print STDOUT header; print STDOUT start_html('Sovereign Brittany Questionnaire'); #### # # Okay - next we will verify *all* the fields on the order # form are listed properly, and verify their correctness. # If those conditions are met, then we'll print out what the # email will look like, and save it off to a variable that we # can pipe to the email program. # #### $your_email_address = param('your_email_address'); $your_name = param('your_name'); $email_subject_line = param('email_subject_line'); $required_fields = param('required_fields'); $thank_you_title = param('thank_you_title'); $return_link_url = param('return_link_url'); $return_link_name = param('return_link_name'); $client_email = param('client_email'); $client_name = param('client_name'); $client_phone = param('client_phone'); $tell = param('tell'); $owned = param('owned'); $lookingfor = param('lookingfor'); $how = param('how'); $fenced = param('fenced'); $time = param('time'); $sex = param('sex'); $house = param('house'); $out = param('out'); $comp = param('comp'); $comments = param('comments'); #### # # So - lets print out some HTML to show them what they ordered, # and get verification that it's all good. # #### $inquiry = ""; $inquiry .= " Email: $client_email\n"; $inquiry .= " Name: $client_name\n"; $inquiry .= " Phone: $client_phone\n"; $inquiry .= " ---------------------------------------- +------------------\n"; if ( length($tell) > 1 ) { $inquiry .= "Please tell us a little about your home and famil +y (including number of children and ages at home). \n"; $inquiry .= "$tell\n"; $inquiry .= "_____________________________________________________ +______________________\n"; } if ( length($owned) > 1 ) { $inquiry .= "Have you owned a dog/Brittany (raised a puppy)? \ +n"; $inquiry .= "$owned\n"; $inquiry .= "_____________________________________________________ +______________________\n"; } if ( length($lookingfor) > 1 ) { $inquiry .= "What are you looking for in a Brittany? \n"; $inquiry .= "$lookingfor\n"; $inquiry .= "_____________________________________________________ +______________________\n"; } if ( length($how) > 1 ) { $inquiry .= "If you are looking for a hunting dog, how often d +o you hunt? Will you be using a professional trainer? \n"; $inquiry .= "$how\n"; $inquiry .= "_____________________________________________________ +______________________\n"; } if ( length($fenced) > 1 ) { $inquiry .= "Do you have a fenced in yard? \n"; $inquiry .= "$fenced\n"; $inquiry .= "_____________________________________________________ +______________________\n"; } if ( length($sex) > 1 ) { $inquiry .= "Are you looking for a male or female, or open to +either? \n"; $inquiry .= "$sex\n"; $inquiry .= "_____________________________________________________ +______________________\n"; } if ( length($house) > 1 ) { $inquiry .= "Where will this puppy/dog live? Where will it stay when you are not home? \n"; $inquiry .= "$house\n"; $inquiry .= "_____________________________________________________ +______________________\n"; } if ( length($out) > 1 ) { $inquiry .= "Will there be someone home during the day to take + the puppy out? \n"; $inquiry .= "$out\n"; $inquiry .= "_____________________________________________________ +______________________\n"; } if ( length($comp) > 1 ) { $inquiry .= "Do you have any interest in competing with your d +og (ie. conformation shows, hunt tests, field trials, agility, obedience, rally, lure coursing, barn hunt, etc)? \n"; $inquiry .= "$comp\n"; $inquiry .= "_____________________________________________________ +______________________\n"; } if ( length($comments) > 1 ) { $inquiry .= "Additional Comments:\n"; $inquiry .= "$comments\n"; $inquiry .= "_____________________________________________________ +______________________\n"; } #### # # Now we've got the order as it was displayed to the user # in the last script stuck inside a variable. We can send # that out in an email to the required email addresses, *and* # print it on the screen for the user again to make sure its # perfect, but there's no going back now... # #### print STDOUT h3({-align=>'center'}, font( {-color=>"#AF0000"}, "Sovereign Brittany Questionnaire" ) ), " +\n"; print STDOUT hr( {-noshade} ), "\n"; print STDOUT "<pre>\n"; print STDOUT $inquiry; print STDOUT "</pre>\n"; print STDOUT "<hr><div align=\"center\">\n"; print STDOUT "<h2 align=\"center\">$thank_you_for_your_filling_out +_our_questionnaire</h2>\n"; #### # # On a windows system, the mail command may need to change # I don't have one to test with, but the lines that say # "open ( MAILx" are the ones that you'll need to fuss with... # #### if ( open (MAIL1, "| mail -s \"$email_subject_line\" $client_email +") != 0 ) { print MAIL1 $inquiry; close MAIL1; } else { print STDOUT "<p>Mail failed to $client_email</p>\n"; } if ( open (MAIL2, "| mail -s \"$email_subject_line\" $your_email_a +ddress") != 0 ) { print MAIL2 $inquiry; close MAIL2; print STDOUT "<p>Mail sent to $your_email_address (to process +this inquiry)</p>\n"; } else { print STDOUT "<p>Mail FAILED to $your_email_address (Will NOT +process this inquiry)</p>\n"; } print STDOUT "<p>click <a href=\"$return_link_url\">$return_link_n +ame</a> to return.</p>\n"; print STDOUT "</div>\n"; } else { #### # # Somehow they got here without going to the order form html # page... so lets just print out an error and tell them to hit # a link to the contact.html page # #### print STDOUT header; print STDOUT start_html('Error'); print STDOUT h1( {-align=>'center'}, font( {-color=>'#AF0000'}, "Error") ), "\n"; print STDOUT hr( {-noshade} ), "\n"; print STDOUT div( {-align=>'center'}, "Please return to the ", a({-href=>'index.html'}, "Sovereign Brittanys.") , "\n", "instead of calling this CGI directly\n"), "\n"; } #### # # That's all folks :-) # #### print STDOUT end_html, "\n";

Replies are listed 'Best First'.
Re: pearl script working but is changing to attachment
by karlgoethebier (Abbot) on Feb 16, 2018 at 11:39 UTC

    Or $inquiry .= "_" x75 . qq(\n); - if i counted right.

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re: pearl script working but is changing to attachment
by johngg (Canon) on Feb 16, 2018 at 15:24 UTC

    To expand on AnomalousMonk's reply, which should save you a heap of typing in the future, HEREDOCs interpolate by default and double quotes do not need to be escaped. Neither do you need explicit line terminators. Note also that, unless you have used select to nominate a different filehandle, STDOUT is the default handle for output and does not need to be supplied to print. To stop interpolation do print <<'EOT'; instead, look at the documentation for more.

    This script

    use strict; use warnings; my $your_email_address = q{fred.bloggs@worthy.com}; my $your_name = q{Fred Bloggs}; print <<EOT; <input type="hidden" name="your_email_address" value="$your_email_addr +ess"> <input type="hidden" name="your_name" value="$your_name"> EOT

    Produces this output

    <input type="hidden" name="your_email_address" value="fred.bloggs@wort +hy.com"> <input type="hidden" name="your_name" value="Fred Bloggs">

    I hope this is helpful.

    Cheers,

    JohnGG

Re: pearl script working but is changing to attachment
by Your Mother (Archbishop) on Feb 16, 2018 at 19:46 UTC

    Chiming in to say that I would be extremely cautious about using any code you got from "Cimmaron Design." These CGIs are written in a style squarely from the 1990s, c MSA, and show a simplistic understanding of Perl and CGI. I would expect the author to have a similar level of skill with web security which is a difficult topic even for seasoned hackers. Depending on your server setup and the code in question, you could end up with real problems.

    Perl like this being deployed in 2018 also makes Perl look bad in my estimation.

      Perl like this being deployed in 2018 also makes Perl look bad in my estimation.

      you say that like its a consideration for random ops tryin to get stuff done or make fun of you

        I say that like someone posted some perl on Perl Monks that makes PHP look like a fabulous option and no one else had pointed it out; an implicit approval which is credibility issue. I almost rewrote it just because it does bother me that much. I don't post my own garbage code here and if I did I would expect exactly the kind of the feedback I gave. I didn't appreciate the strict approach as a n00b but over time I learned to because it's a part of why I make a good living slinging Perl. The place insists on professionalism to everyone's benefit and while off-topic and dangerous shortcuts are often entertained, and should be, they are rarely let pass without comment.

        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: pearl script working but is changing to attachment
by AnomalousMonk (Archbishop) on Feb 16, 2018 at 14:06 UTC
Re: pearl script working but is changing to attachment
by poj (Abbot) on Feb 16, 2018 at 07:27 UTC

    Try replacing this line in part 2

        $inquiry .= "             ----------------------------------------------------------\n

    with

        $inquiry .= "___________________________________________________________________________\n";
    poj
Re: pearl script working but is changing to attachment
by Anonymous Monk on Feb 16, 2018 at 11:38 UTC
    Make and use subroutines! Welcome to second day of programming :)