in reply to Re: CGI Recipient
in thread CGI Recipient

Sorry about being so vague. here is a snip of the code:
$mailprog = '/usr/lib/sendmail'; # Recipient of form responses $recipient = 'test@test.edu'; # Print out a content-type for HTTP/1.0 compatibility print "Content-type: text/html\n\n"; # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # Stop people from using subshells to execute commands # Not a big deal when using sendmail, but very important # when using UCB mail (aka mailx). # $value =~ s/~!/ ~!/g; # Uncomment for debugging purposes # print "Setting $name to $value<P>"; $FORM{$name} = $value; } # Print title and header info for user response &user_response; $date = `date`; # Now send mail to $recipient formatted in HTML # Note: MIME, Subject and Content lines must appear EXACTLY as they do + below # (only one \n after Subject line!) open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n"; print MAIL "Reply-to: $FORM{'email'} ($FORM{'name'})\n"; print MAIL "MIME-Version: 1.0\n"; print MAIL "Subject: ES Internal Routing Form> $FORM{'name'}: $FORM{'i +d'} \n"; print MAIL "Content-Type: text/html; charset=us-ascii\n"; print MAIL "Content-Transfer-Encoding: 7bit\n"; print MAIL "<html><head>\n"; print MAIL "<title>HR "; print MAIL "ES Internal Routing Form</title>\n"; print MAIL "</head>\n"; print MAIL "<body bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#003366\ +" "; print MAIL "alink=\"#666666\" vlink=\"#6699CC\">\n"; print MAIL "<center><table border=0 width=99%>"; print MAIL "<tr><td align=left>"; print MAIL "<img src=\"HR/graphics/smdbw_logo.gif\" "; print MAIL "alt=\"logo\"></td>"; print MAIL "<td align=center><font color=\"#003366\" size=+2>"; print MAIL "Office<br>"; print MAIL "ES Internal Routing Form</font></td></tr>"; print MAIL "</table>"; print MAIL "<img src=\"graphics/2lines.gif\" "; print MAIL "alt=\"2lines\"></center>"; print MAIL "<font color=\"#FF0000\"><b>Processed By: </b>$FORM{'fnba'} + $FORM{'estb'} $FORM{'espr'}</font><br>"; print MAIL "<b>Name: </b>$FORM{'name'}<br>"; print MAIL "<b>SS#: </b>$FORM{'ss'}<br>"; print MAIL "<b>ID#: </b>$FORM{'id'}<br>"; print MAIL "<b>Dept: </b>$FORM{'deptnumber'}<br>"; print MAIL "<b>Title: </b>$FORM{'title'}<br>"; print MAIL "<b>US Citizen? </b>$FORM{'ckusyes'} $FORM{'ckusno'}<br>";
When the user selects $FROM {'ckusno') I would like for an additional recipient be added to the form. GD

Replies are listed 'Best First'.
•Re: Re: Re: CGI Recipient
by merlyn (Sage) on Mar 04, 2004 at 19:33 UTC
Re: Re: Re: CGI Recipient
by iburrell (Chaplain) on Mar 04, 2004 at 21:42 UTC
    First, you can send to multiple email addresses by putting them as arguments to sendmail. That is, a space separated string.
    $recipient = "foo@example.com bar@example.com";
    Second, you aren't formatting the email correctly. There must be a blank line between the header and the body.

    Third, you should include a To: line in the header with a list of the email addresses being sent to (separated by commas). sendmail will not add the header automatically. If you don't, the mail will show "To: undisclosed-recipients;". And probably be filtered out by spam filters. Sendmail will read the list of addresses from the To: header if you use the "-t" command line switch.

      It is not sending to the multiple email addresses that I am having a problem with, although, your tip on the formatting is a huge help. What I am looking for is to take the field
      print MAIL "<b>US Citizen? </b>$FORM{'ckusyes'} $FORM{'ckusno'}<br>";
      When the 'ckusno' is true or slected then an additional email recipient is added. I don't want to inundate the additional recipient with every form, only when this field is valid. Thanks,
Re: Re: Re: CGI Recipient
by arden (Curate) on Mar 04, 2004 at 19:19 UTC
    Just include a test for the selection and if it's true, set $recipient to 'test@test.edu' and 'additional@test.edu' before you call  open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";

    - - arden.

      I was going down this route initially if ($FORM{'ckusr'}<=> " ") { $recipient = 'test@test.edu','test1@test.edu; } else { $recipient = 'test@test.edu';
      Sorry about the blanks, a little hicup I was going down this route
      if ($FORM{'ckusr'}<=> " ") { $recipient = 'test@test.edu','test1@test.edu; } else { $recipient = 'test@test.edu';
      GD Thanks for the input by the way.