Solved

Question: Handle multiple email receipients with checkmarks - Part Two

Posted on 2001-06-19
17
380 Views
Last Modified: 2013-12-25
Hello All,

This question is for a modification of a script provided in answer of this closed Question at this link:

http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=cgi&qid=20134243

rag2000 provided the winning answer, and now my client requests a modification.  The site is live and I would appreciate the modification of the script as soon as possible :)

In summary, I have a form at the following location:

http://www.calcommuters.org/bay_area/email.html  

(NOTE: The site is live, so please do not actually use the form!)

The script provided by rag2000 answered my question to send emails to the checkmarked recipients.

However here is the modification I now need:

1)  I need the names of the check-marked recipients also included in the information that is sent to the database, along with the other information that is sent there.

2   I need the date the form was submitted also sent to the database in the following or similar format: 01/23/01.  (month, date, and year)  

2)  I would also like to eliminate the script's requirement of the following portion because the email addresses will be continually be modified, with emails being added and subtracted.

for($e=1;$e<25;$e++){

Okay now, here is rag200's script:

#!/usr/bin/perl

    $|++;
    use CGI;

    $cgi=new CGI;
    $emailAddress=$cgi->param('emailAddress');
    $firstName=$cgi->param('firstName');
    $firstName=~s/'/''/g;
    $lastName=$cgi->param('lastName');
    $lastName=~s/'/''/g;
    $cityResidence=$cgi->param('cityResidence');
    $cityResidence=~s/'/''/g;
    $emailSubject=$cgi->param('emailSubject');
    $emailSubject=~s/'/''/g;
    $yourMessage=$cgi->param('yourMessage');
    $yourMessage=~s/'/''/g;

    open(MAIL, "|/usr/lib/sendmail -t");
    print MAIL "From: $emailAddress\n";
    print MAIL "To: you\@yourDomain.com\n";
    print MAIL "Subject: $emailSubject\n";
    print MAIL "\n";
    print MAIL "$yourMessage";
    close MAIL;

    for($e=1;$e<25;$e++){
         $s="checkbox$e";
         $mailPerson=$cgi->param($s);
         if($mailPerson ne ""){
              open(MAIL, "|/usr/lib/sendmail -t");
              print MAIL "From: 'California Commuters Alliance'<you\@yourDomain.com>\n";
              print MAIL "To: $mailPerson\n";
              print MAIL "Subject: $emailSubject\n";
              print MAIL "\n";
              print MAIL "$yourMessage";
              close MAIL;
              $mailedTo.="$mailPerson|";
         }
    }

    open (LOGG, ">>path to databases/bay-areaDb.txt");
    print LOGG "$emailAddress|$firstName|$lastName|$cityResidence|$emailSubject|$yourMessage|$mailedTo\n";
    close (LOGG);

    print "Content-type: text/html \n\n";
    open(HANDLE, "path to thankyou/email_thankyou.html") || print "could not open thanks";
    while(<HANDLE>){
         $_=~s/grfx/..\/grfx/g;
         print $_;
    }


===== END OF SCRIPT===

That's it!

THanks to rag2000 for his script and to anyone who can help with this new modification.

Rowby
0
Comment
Question by:Rowby Goren
  • 9
  • 8
17 Comments
 
LVL 3

Expert Comment

by:rag2000
Comment Utility
I am here again, just hang on, solution coming in
0
 
LVL 3

Expert Comment

by:rag2000
Comment Utility
I see that you have used absolute url's for the images, in that case, you may delete this line, it is no longer required

$_=~s/grfx/..\/grfx/g;
0
 
LVL 3

Expert Comment

by:rag2000
Comment Utility
for query (1), you will need to modify the html form like shown here below to include the names of the persons along with their emails addresses, splitting on the pipe character will be done by the cgi to send them in as two entities, please modify each of the checkboxes. The modified cgi below takes care of your requirement.

<input type="checkbox" name="checkbox1" value="Metropolitan Transportation Commission Chair Sharon. J. Brown|sharonsell@aol.com">

-----------------------

for query (2), add this to the form

<input type="hidden" name="todayDate">
<script language="JavaScript">
<!--
     now = new Date()
     year = now.getFullYear()
     month = now.getMonth()
     month = month+1;
     if(month<10) month = "0" + String(month);
     day = now.getDate()
     if(day<10) day = "0" + String(day);
     today = (month+'-'+day+'-'+year)
     document.email_form.todayDate.value=today;
//-->
</script>

the changed cgi script as below will pick up this date and post to the database.

-----------------------

for query (3), just add this one hidden field to the form which is the count of checkboxes plus one in the form

<input type="hidden" name="mailHandler" value="25">

-----------------------

#!/usr/bin/perl

   $|++;
   use CGI;

   # this reads the form basic input
   $cgi=new CGI;
   $emailAddress=$cgi->param('emailAddress');
   $firstName=$cgi->param('firstName');
   $firstName=~s/'/''/g;
   $lastName=$cgi->param('lastName');
   $lastName=~s/'/''/g;
   $cityResidence=$cgi->param('cityResidence');
   $cityResidence=~s/'/''/g;
   $emailSubject=$cgi->param('emailSubject');
   $emailSubject=~s/'/''/g;
   $yourMessage=$cgi->param('yourMessage');
   $yourMessage=~s/'/''/g;
   $mailHandler=$cgi->param('mailHandler');
   $todayDate=$cgi->param('todayDate');

   # this section sends the notification email to you
   # that somebody has submitted the message
   open(MAIL, "|/usr/lib/sendmail -t");
   print MAIL "From: $emailAddress\n";
   print MAIL "To: you\@yourDomain.com\n";
   print MAIL "Subject: $emailSubject\n";
   print MAIL "\n";
   print MAIL "$yourMessage";
   close MAIL;

   # this section sends the emails to the selected recipients
   for($e=1;$e<$mailHandler;$e++){
        $s="checkbox$e";
        $mailPerson=$cgi->param($s);
     @mailPerson=split('|',$mailPerson);
        if($mailPerson[1] ne ""){
             open(MAIL, "|/usr/lib/sendmail -t");
             print MAIL "From: 'California Commuters Alliance'<you\@yourDomain.com>\n";
             print MAIL "To: $mailPerson[1]\n";
             print MAIL "Subject: $emailSubject\n";
             print MAIL "\n";
             print MAIL "$yourMessage";
             close MAIL;
             $mailedTo.="|$mailPerson[0]|$mailPerson[1]";
        }
   }

   # this displays the thanks page once the form has been submitted
   open (LOGG, ">>path to databases/bay-areaDb.txt");
   print LOGG "$emailAddress|$firstName|$lastName|$cityResidence|$emailSubject|$yourMessage$mailedTo|$todayDate\n";
   close (LOGG);

   print "Content-type: text/html \n\n";
   open(HANDLE, "path to thankyou/email_thankyou.html") || print "could not open thanks";
   while(<HANDLE>){
        print $_;
   }
0
 
LVL 9

Author Comment

by:Rowby Goren
Comment Utility
Much appreciated!

Am at a client's and will install the code and the mdofications tonight.

Rowby
0
 
LVL 9

Author Comment

by:Rowby Goren
Comment Utility
Hi, working on modifying the form now, and am adding the hidden fields, etc.

I would prefer not to have even the
<input type="hidden" name="mailHandler" value="25"> -- so I wouldn't even have to change that on the pages, whenever emails are added and removed.

But perhaps you can educate me on the necessity for that item. Is it for security reasons?

What would happen if I made the value to "100" for instance.

Thanks,


Rowby
0
 
LVL 9

Author Comment

by:Rowby Goren
Comment Utility
Hi,

For some reason i'm getting an error message, which you can try for yourself by going to:

http://www.calcommuters.org//bay_area/email.html

You don't have to fill out anything in the form -- just  hit the submit button. (I have a hidden field called  <input type="hidden" name="checkbox24" value="Rowby Goren|rowby@rowby.com"> so I can receive all of the emails.)

The error message appears after the submit is hit:

User unknown /local/home/b1050/dead.letter... Saved message in /local/home/b1050/dead.letter Content-type: text/html


====
My client has said the site won't be live for a few more days, so it's no "crisis", but could you look at it and tell me what I might need to do.

ALSO, I don't *need* to have the names of the of People associated with their emails -- it's a nice feature, but not required -- and I'll keep it.  

What I need is the checkmarked email addresses (and the names of the recipients -- but not required) to be sent to the database so my client will know exactly to which government official the various emails were sent.  This can be either (or both) the name of the email recipient as well as their email address.

Just wanted to make it clear -- that your earlier form handler script only sent the name of the sender, their email address etc  to the database -- without the client knowing which government officials received those emails.

Not knowing perl, but looking at your latest script, it does not appear that the log is receiving the emails/names of the checkmarked recipients.

"$emailAddress|$firstName|$lastName|$cityResidence|$emailSubject|$yourMessage$mailedTo|$todayDate\n";
  close (LOGG);


THanks
0
 
LVL 3

Expert Comment

by:rag2000
Comment Utility
$mailedTo does send the email addresses of all the recipients to the text database.

will it be possible for me to login to your server and correct the problem... it will be faster and simpler

dead.letter... every mail going out of the server needs to have a valid address else it bounces back to the server and gets saved as dead.letter
0
 
LVL 9

Author Comment

by:Rowby Goren
Comment Utility
Yes.  Email me at rowby@rowby.com and I will send you the ftp info.

Rowby
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:rag2000
Comment Utility
after waiting for the ftp info by mail, i though i might as well make the clarifications here...

the first mail that goes out to you or the admin of the site stating that a form submission has taken place, should have the correct email inserted instead of you@yourDomain.com and don't forget the \ preceeding the @

  print MAIL "From: $emailAddress\n";
  print MAIL "To: you\@yourDomain.com\n";

the second set of mails that go out to the recipients

  print MAIL "From: 'California Commuters Alliance'<you\@yourDomain.com>\n";
  print MAIL "To: $mailPerson[1]\n";

should also have the necessary changes

i checked your form, some of the recipients do not have the name in the <input tag.... name|email>, rather the pipe is not there, and the script splits the info on the pipe character.

you will need the input tag mailHandler with the value set to the number of checkboxes so that the for loop does not waste time by doing extra loops... just give me a day, and i'll write a routine or rather optimize the script and the form. bye.
0
 
LVL 9

Author Comment

by:Rowby Goren
Comment Utility
Hi,

It is always an educational experience for me at the Experts-Exchange. And as usual I'm the "DUH".  I should have seen those things I should have added.

But in any case, take the day and I'll wait for the optimized script.

In the meantime I'll fix those <input tag.... name|email>,
thingies.

And if you send me an email at rowby@rowby.com I'll give you the ftp info

Thanks again,

Rowby
0
 
LVL 9

Author Comment

by:Rowby Goren
Comment Utility
FYI I will be fixing the HTML code early in the morning (Pacific Coast Morning)

Rowby
0
 
LVL 9

Author Comment

by:Rowby Goren
Comment Utility
Raq2000:  "after waiting for the ftp info by mail, i though i might as well make the clarifications here.."

Hi I don't see your email address posted among the comments which is why I haven't you the ftp info.  My email address is rowby@rowby.com

I will be here to respond to your email request for the ftp info for about 3 more hours.

Anyway I'm going in now and fix the html and the perl based on your recent comments.

THanks

Rowby
0
 
LVL 3

Expert Comment

by:rag2000
Comment Utility
creative@dte.vsnl.net.in
rag-2000@excite.com
0
 
LVL 3

Accepted Solution

by:
rag2000 earned 250 total points
Comment Utility
Hi Rowby,

Now that the script is working fine on your server, and I have also mailed the optimized version to you, could you please close this quextion???
0
 
LVL 9

Author Comment

by:Rowby Goren
Comment Utility
Hi Here's the script that is installed and working.

And thanks for all your help!



    foreach $referer (@referers){
      if($ENV{'HTTP_REFERER'}=~m|$referer|){
        $check_referer=1;
        last;
      }
    }
  }

  # if referer is invalid, access is denied
  if($check_referer!=1){
     print "Content-type: text/html\n\n";
     print "<center><h1>Access Denied<\/h1><\/center>";
     exit;
  }

  # this reads the form basic input
  $cgi=new CGI;
  $emailAddress=$cgi->param('emailAddress');
  $firstName=$cgi->param('firstName');
  $lastName=$cgi->param('lastName');
  $cityResidence=$cgi->param('cityResidence');
  $emailSubject=$cgi->param('emailSubject');
  $yourMessage=$cgi->param('yourMessage');
  $mailHandler=$cgi->param('mailHandler');
  $todayDate=$cgi->param('todayDate');

  # this section sends the notification email to you
  # that somebody has submitted the message
  open(MAIL, "|/usr/lib/sendmail -t");
  print MAIL "From: $emailAddress\n";
  print MAIL "To: Mobility2\@calcommuters.org\n";
  print MAIL "Subject: $emailSubject\n";
  print MAIL "\n";
  print MAIL "$yourMessage";
  print MAIL "\n\n";
  print MAIL "$firstName $lastName";
  print MAIL "$emailAddress";
  close MAIL;

  # this section sends the emails to the selected recipients
  for($e=1;$e<$mailHandler;$e++){
       $s="checkbox$e";
       $mailPerson=$cgi->param($s);
        @mailPerson=split("#",$mailPerson);
       if($mailPerson[1] ne ""){
            open(MAIL, "|/usr/lib/sendmail -t");
            print MAIL "From: $emailAddress\n";
            print MAIL "To: $mailPerson[1]\n";
            print MAIL "Subject: $emailSubject\n";
            print MAIL "\n";
            print MAIL "$yourMessage";
            print MAIL "\n\n";
            print MAIL "$firstName $lastName";
            print MAIL "$emailAddress";
            close MAIL;
            $mailedTo.="|$mailPerson[0]|$mailPerson[1]";
       }
  }

  # this displays the thanks page once the form has been submitted
  open (LOGG, ">>/local/home/b345/domains/calcommuters.org/public_html/www.calcommuters.org/bay-areaDb.txt");
  print LOGG "$emailAddress|$firstName|$lastName|$cityResidence|$emailSubject|$yourMessage$mailedTo|$todayDate\n";
  close (LOGG);

  print "Content-type: text/html \n\n";
  open(HANDLE, "/local/home/b345/domains/calcommuters.org/public_html/www.calcommuters.org/email_thankyou.html") || print "could not open thanks";
  while(<HANDLE>){
       print $_;
  }
0
 
LVL 3

Expert Comment

by:rag2000
Comment Utility
thanks for the opportunity to help
0
 
LVL 9

Author Comment

by:Rowby Goren
Comment Utility
After the solution was posted Ran2000 made some futher enhancements of the script.  I am posting it below.  Included is the requirement that the script receive its call from a specificed url and the exporting of the database in a comma delimitated format for exporting into external database.

#!/usr/bin/perl

     $|++;
     use CGI;

     # list of valid referers
     @referers = ('http://www.calcommuters.org/bayarea/email.html');

     # the following checks to see if the call is coming from one of the vaild referers
     $check_referer=0;
     if($ENV{'HTTP_REFERER'}){
          foreach $referer (@referers){
               if($ENV{'HTTP_REFERER'}=~m|$referer|){
                    $check_referer=1;
                    last;
               }
          }
     }

     # if referer is invalid, access is denied
     if($check_referer!=1){
          print "Content-type: text/html\n\n";
          print "<center><h1>Access Denied<\/h1><\/center>";
          exit;
     }

     # this reads the form basic input
     $cgi=new CGI;
     $emailAddress=$cgi->param('emailAddress');
     $firstName=$cgi->param('firstName');
     $lastName=$cgi->param('lastName');
     $cityResidence=$cgi->param('cityResidence');
     $emailSubject=$cgi->param('emailSubject');
     $yourMessage=$cgi->param('yourMessage');
     $yourMessage=~s/\s*\n\s*/ /g;
     $mailHandler=$cgi->param('mailHandler');
     $todayDate=$cgi->param('todayDate');

     # this section sends the notification email to you
     # that somebody has submitted the message
     open(MAIL, "|/usr/lib/sendmail -t");
     print MAIL "From: $emailAddress\n";
     print MAIL "To: Mobility8\@commuters.org\n";
     print MAIL "Subject: $emailSubject\n";
     print MAIL "\n";
     print MAIL "$yourMessage";
     print MAIL "\n\n";
     print MAIL "$firstName $lastName";
     print MAIL "$emailAddress";
     close MAIL;

     # this section sends the emails to the selected recipients
     for($e=1;$e<$mailHandler;$e++){
          $s="checkbox$e";
          $mailPerson=$cgi->param($s);
          @mailPerson=split("#",$mailPerson);
          if($mailPerson[1] ne ""){
               open(MAIL, "|/usr/lib/sendmail -t");
               print MAIL "From: $emailAddress\n";
               print MAIL "To: $mailPerson[1]\n";
               print MAIL "Subject: $emailSubject\n";
               print MAIL "\n";
               print MAIL "$yourMessage";
               print MAIL "\n\n";
               print MAIL "$firstName $lastName";
               print MAIL "$emailAddress";
               close MAIL;
          }
          $mailedTo.=",\"$mailPerson[0]\",\"$mailPerson[1]\"";
     }

     # this displays the thanks page once the form has been submitted
     open (LOGG, ">>/local/home/www/commuters.org/www.calcommuters.org/form-databases/datab.txt");
     print LOGG "\"$emailAddress\",\"$firstName\",\"$lastName\",\"$cityResidence\",\"$emailSubject\",\"$yourMessage\"$mailedTo,\"$todayDate\"\n";
     close (LOGG);

     print "Content-type: text/html \n\n";
     open(HANDLE, "/local/home/www/commuters.org/www.calcommuters.org/email_thankyou.html") || print "could not open thanks";
     while(<HANDLE>){
          print $_;
     }

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now