I have a script that was originally just supposed to send an e-mail to a user with the responses from an evaluation form.
I have just been told that we now want not only the e-mail sent, but also for one section of the evaluation to be inserted into a database.
I had a script that did that in another part of our project. I have tried to combine the two scripts but am running into problems.

I think there is a problem with having both processes in this script. At one point, I had the form responses being inserted into the database,
but no e-mail being sent. Now I have the e-mail sent, but no database insertion. It changes depending on where I put the statements.

How can I get both things accomplished? Or is this just a dumb error on my part?

I'll warn you... I am a Perl newbie.

#!/usr/local/bin/perl5.005 use lib '../lib'; use DBI(0.90); use strict; use Database; use CGI qw(:standard); Database::->db_info_path("../lib/db.cfg"); my $dbh = new Database; #Grab the evaluation responses from the form my $cdsid = param('cdsid'); my $title = param('Title'); my $author = param('Author'); my $book_review = param('book_review'); my $post_review = param('post_review'); my $use_name = param('use_name'); my $sendmail = '/usr/lib/sendmail'; my $recipient = 'mbelang3@ford.com'; my $sender = 'e-Books Feedback <plskills@ford.com>'; my $site_name = 'e-Courses'; my $site_url = '../e-course.html'; my $site_name2 = 'e-Books'; my $site_url2 = '../e-books.html'; my $value; my $field; my $email; my $name; my $query = new CGI; my $mail_body = ''; foreach $field (sort ($query->param)) { foreach $value ($query->param($field)) { $mail_body .= "$field: $value\n"; } } if (($email = $query->param('07_email')) and ($query->param('07_email') =~ /@/)) { if ($name = $query->param('cdsid')) { $name =~ s/"//g; $sender = "\"$name\" <$email>"; } else { $sender = "$email"; } } open(MAIL, "|$sendmail -oi -t") or die "Can't open pipe to $sendmail: +$!\n"; print MAIL "To: $recipient\n"; print MAIL "From: $sender\n"; print MAIL "Subject: e-Books Feedback\n\n"; print MAIL "$mail_body"; close(MAIL) or die "Can't close pipe to $sendmail: $!\n"; #Declare variables for insertion constants my $plselect = "u"; my $updt = "L2e Init"; #Insert the e-Book review and book information into il2e009_bk_review if ($book_review) { my %review = ('il2e009_book_title_x',$title,'il2e009_book_author_x',$a +uthor, 'il2e009_eval_cds_id_c',$cdsid,'il2e009_pl_select_f',$plselect,'il2e00 +9_post_rev_f', $post_review,'il2e009_post_name_f', $use_name,'il2e009_review_x',$book +_review,'il2e009_last_updt_c',$updt); foreach my $key (keys %review) { print "$key = $review{$key}\n"; } print "Attempting insert....\n"; $dbh->insert_row('il2e009_bk_review',\%review); } $dbh->disconnect;

In reply to Problems Trying to Send E-Mail and Insert into Database by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.