Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert input from a drop down menu into an email

Status
Not open for further replies.

Gilgalad

IS-IT--Management
Mar 5, 2003
4
US
I manage the IT for a small insurance firm and am pretty new to .CGI so bear with me. I would like to create a drop down menu for users to input info (no problem so far) and, upon submission of it, transfer it into either a text file which can automatically and immeadiately be attached to their email program, or input it directly into their default email program. The goal is for the user to input the data, click on submit, watch the default mail program open and click send. If I could get some guidence, pointers on where to start, or even appropriate resources to confer I would greatly appreciate it.

Cheers, Robert
 
Why not send the mail directly from the server?

Can you determine who is accessing the page, to lookup their e-mail address, you can then have the server send the mail on their behalf, and copy them if they need to have it in their inbox.

AFAIK, cgi cannot access resources on a client machine without intervention from a user, so having the cgi open the mail program and send the mail automatically is "probably" unfeasible.

I'll post a short mail script l8r on

HTH
;P
 
Robert, thsi assume access to sendmail on a Linux/unix box, there are simpler mailers for NT such as softmail

Code:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
use Socket;
#use MIME::Entity;

my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime();$pid=$$;
local %form = &get_form_data;
$File = "P$hour$min$sec$year$yday-$pid.htm";

    &writefile;
    &sendemail;  
    &gen_conf;

sub sendemail {

    $sender = &getsender;
    local($print_config,$key,$sort_order,$sorted_field,$env_report); 
    $mailprog = '/usr/sbin/sendmail';
    $auto_type = 'text/plain';
    $auto_encoding = 'base64';
    $auto_body = 'body.txt';
    $message_type = 'multipart/mixed'; 
    $log_or_email = 'B';
    $email_log = 'automail_lite.log';
    $Body="Guess what";
    $top = build MIME::Entity Type => $message_type,
                          From => "webserver\@myserver.com",
                          To => "$sender",
                          Subject => "New query from webserver"; 
    attach $top Data=> $Body;
    attach $top Path => "$File",Type => $auto_type,Encoding => $auto_encoding; 
    open MAIL, "|$mailprog -t -i" or die "open: $!";
        $top->print(\*MAIL);
    close MAIL; 
    my @file ="$File";
    unlink @file;
}
sub writefile {
    open TXT, ">$File";
    print TXT &quot;<html>\n&quot;;
    print TXT &quot;<body>\n&quot;;
    print TXT &quot;<table width=\&quot;60%\&quot;>\n&quot;;
    print TXT &quot;   <tr>\n&quot;;
    print TXT &quot;     <td>Name:</td><td>$form{'name'}</td>\n&quot;;
    print TXT &quot;   </tr>\n&quot;;
    print TXT &quot;   <tr>\n&quot;;
    print TXT &quot;     <td>Telephone</td><td>$form{'tel'}</td>\n&quot;;
    print TXT &quot;   </tr>&quot;;
    print TXT &quot;   <tr>&quot;;
    print TXT &quot;     <td>email</td><td>$form{'fax'}</td>\n&quot;;
    print TXT &quot;   </tr>\n&quot;;
    print TXT &quot;   <tr>&quot;;
    print TXT &quot;     <td>email</td><td>$form{'email'}</td>\n&quot;;
    print TXT &quot;   </tr>\n&quot;;
    print TXT &quot;   <tr>\n&quot;;
    print TXT &quot;     <td>interest</td><td>$form{'query'}</td>\n&quot;;
    print TXT &quot;   </tr>\n&quot;;
    print TXT &quot;</table>\n&quot;;
    print TXT &quot;</body>\n&quot;;
    print TXT &quot;</html>\n&quot;;

}

sub getsender {
   $seed = $form{'user'};
   my $mail_trgt;
   open INP,&quot;<mail.txt&quot;;
   while (<INP>) {
     my ($name, $email) = split /::| /,$_ ;
     if (&quot;$name&quot; eq &quot;$seed&quot;) {
     	$mail_trgt = $email;
     }
   }
   close (INP);
   return &quot;$mail_trgt&quot;;
}

sub gen_conf {

print &quot;<font face=\&quot;Verdana\&quot; size=\&quot;2\&quot; color=\&quot;#008000
\&quot;>Your query has been queued<br>We will be in touch at our 
earliest convenience<br><br>Thank you for your query&quot;;
}

sub get_form_data {
        my $temp;
        my $buffer;
        my @data;
        my $count = 0;
        read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
        foreach $temp (split(/&|=/,$buffer)) {
                $temp =~ tr/+/ /;
                $temp =~ s/%([0-9a-fA-F]{2})/pack(&quot;c&quot;,hex($1))/ge;
        $temp =~ s/[\r\n]/ /g;
                push @data, $temp;
        }
        foreach $temp (split(/&|=/,$ENV{'QUERY_STRING'})) {
                $temp =~ tr/+/ /;
                $temp =~ s/%([0-9a-fA-F]{2})/pack(&quot;c&quot;,hex($1))/ge;
        $temp =~ s/[\r\n]/ /g;
                push @data, $temp;
        }
        return @data;
}
<-- End CGI script

<-- Start HTML
Code:
<html>
<head>
<title>Test Mailer</title>
</head>
<body>
  <form name=&quot;testmail&quot; action=&quot;/cgi-bin/mail.cgi&quot; method=&quot;post&quot;>
   <input type=&quot;hidden&quot; name=&quot;user&quot; value =&quot;whatever&quot;><!-- NAME OF USER TO RECIEVE MAIL -->
   <table>
   	  <tr>
   		<td>Name:</td>
   		<td><input type=&quot;text&quot; name=&quot;name&quot;></input></td>
   	  </tr>
   	  <tr>
   	 	<td>Tel</td>
   		<td><input type=&quot;text&quot; name=&quot;tel&quot;></input></td>
   	  </tr>
   	  <tr>
   		<td>Fax</td>
   		<td><input type=&quot;text&quot; name=&quot;fax&quot;></input></td>
   	  </tr>
   	  <tr>
   		<td>email</td>
   		<td><input type=&quot;text&quot; name=&quot;email&quot;></input></td>
   	  </tr>
   	  <tr>
   		<td>query</td>
   		<td><textarea name=&quot;query&quot;></textarea></td>
   	  </tr>
   	  <tr>
		<td colspan=&quot;2&quot;><input type=&quot;submit&quot; value=&quot;submit&quot;></td>
	  </tr>
	</table>
  </form>
 </body>
</html>
<-- end HTML

<-- start data file [mail.txt in cgi-bin directory, or wherever you want
whatever::me@nowhere.com
whenever::fred@flintstone.com
fred::samovar@coffepots.net
<-- end data file
 
Thx a million Paul, I am on it and will post back any new questions.

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top