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

Dear All, I have created a html web form that has checkboxes for email address to send to based on selection. If a user checked a box called Product Management, it'll should send it to productmgt@domain.com, and if they check that and another checkbox called TechSupport it should also send it to techsupport@domain.com.... I have tried to incorperate that into a very basic Perl script but have failed. I tried searching the web for any documentations on how to do this, boy was that hard, I couldn't find any...Below is an example of the code in the html form, I don't have any for perl because I'm faily new at this and don't know where to go with it.... Appriciate your help!!
<tr> <td> <font size="2"> <input type="checkbox" name="m_EmailGroups" value="Prod_Mgt ">Product +Mgt </font></td> <td> <font size="2"> <input type="checkbox" name="m_EmailGroups" value="TechSupport">Tech S +upport </font></td> </tr>

Replies are listed 'Best First'.
Re: sending email based on form checkbox selection
by erasei (Pilgrim) on Jun 30, 2003 at 19:31 UTC
    This sounds remarkably like you are wanting someone to do some work for you instead of doing it yourself. This is an assignment you'd get in Introductory to Perl in a school class too.

    As far as 'searching the web for any documentations' and not finding any, I find that hard to believe. A quick Google search will return quite a few (most of which are scary).

    In any event, if you really are looking for genuine help, your first stop should be with the Mail::Sender and the CGI modules.

      I have searched Google for almost a week and found most of the solution is already written as an application. I'm looking for something basic help here. I'm not a big time programmer like you are, this is new to me, I'm willing to admit that. But if you want to make a big deal out of this, so be it!! By the way, I'm not looking for anyone to do my work! If you are so arrogant to help someone new to Perl then that's your problem... Remember you were once in my shoes...
        Easy there fellah, don't blow a gasket. I'm not arrogant with my perl knowledge, I use Perl monks for help a lot more than I use it to provide answers.

        However, having said that, your original post looked a lot like a high schooler looking for an easy answer for a programming assignment. If such is not the case, then it's all well and good.

        You want to use the CGI module to take the input from your html form. First step would be to point your html form to your perl script.. something like:

        <FORM METHOD="POST" ACTION="/cgi-bin/button.cgi">

        Then in your perl script you need to create a new cgi object, like so:

        use strict; use Mail::Sendmail; use CGI; my $cgi = new CGI;
        Then get the value of the button that was checked.
        my $button_value = $cgi->param('m_EmailGroups');
        Then you'll need to do whatever comparison you need to do on the $button_value variable, and then send the email:
        my %mail = ( To => 'myhomeaddress@isp.com', From => 'myworkaddress@company.com', Subject => 'Form Submission', Message => "The $button_value button was checked." ); sendmail(%mail) or die $Mail::Sendmail::error;
        All code is untested and offered as a guide. Take it, read it, learn it, change it, use it.