BCC in 'send this URL to a friend' CGI script
I want to include an automatic BCC in the CGI script below. Where's the best place?
***
#!/usr/bin/perl
use Socket;
$|=1;
$SMTP_SERVER="smtp.mail.net";
$SCRIPT_NAME="http://friendscb.org/cgi-bin/recommendfcb.cgi";
$SITE_NAME="Friends of Canadian Broadcasting Web site";
$SITE_URL="http://friendscb.org/";
$ENDLINE="";
$MAXNUM=5;
$LOGFILE="/web/_private/reflog.txt";
if ($SENDMAIL ne "")
{&test_sendmail;}
&valid_page; #if script is called from offsite, bounce it!
&decode_vars;
if ( $ENV{'REQUEST_METHOD'} ne "POST")
{
&draw_request;
exit;
}
&do_log;
&process_mail;
print "Location: $JUMP_TO\n\n";
##################################################################
sub process_mail
{
for ($i=1;$i<$MAXNUM+1;$i++)
{
$recipname="recipname_$i";
$recipemail="recipemail_$i";
if ($fields{$recipemail} eq "")
{
next;
}
if (&valid_address == 0)
{
next;
}
$subject = "Recommendation from $fields{'send_name'}";
$msgtxt = <<__STOP_OF_MAIL__;
Hi $fields{$recipname},
$fields{'send_name'} stopped by the $SITE_NAME
and suggested that you visit the following URL:
$JUMP_TO
__STOP_OF_MAIL__
if ($fields{'message'} ne "")
{
$msgtxt .= "$fields{'send_name'} writes:\n";
$msgtxt .= "$ENDLINE\n";
$msgtxt .= "$fields{'message'}\n\n";
}
$msgtxt .= "************";
$msgtxt .= "$ENDLINE\n";
$msgtxt .= "Subscribe FREE to FRIENDS' E-News at http://friendscb.org/en/enews.htm\n";
$msgtxt .= "Find out what's new with FRIENDS at http://friendscb.org/headlines.htm\n";
$mailresult=&sendmail($fields{send_email}, $fields{send_email}, $fields{$recipemail}, $SMTP_SERVER, $subject, $msgtxt);
if ($mailresult ne "1")
{print "Content-type: text/html\n\n";
print "MAIL NOT SENT. SMTP ERROR: $mailresult\n";
exit
}
}
}
##################################################################
sub draw_request
{
print "Content-type: text/html\n\n";
print <<__REQUEST__;
<TITLE>Recommend FCB to a Friend</TITLE>
<P ALIGN="center"><IMG SRC="http://friendscb.org/images/FCBlogo.jpg" width="226" height="51" alt="FRIENDS Logo" border="0"></p>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<P>
<TABLE WIDTH=550 BGCOLOR="#F7B455">
<TR>
<TD>
<FONT FACE="ARIAL" SIZE=4 COLOR="#000000">
<CENTER>
<B>
<P>
The page you wish to recommend is:<P>
</FONT>
<FONT FACE="ARIAL" SIZE=3 COLOR="#000000">
<A HREF="$ENV{'HTTP_REFERER'}">$ENV{'HTTP_REFERER'}</A>
</CENTER>
</B>
</FONT>
<BLOCKQUOTE>
<FONT FACE="ARIAL" SIZE=2 COLOR="#000000">
<P>
To proceed, simply fill in the e-mail address of the friend(s) you wish to tell, along with your name and e-mail address,
and click the <B>SEND</B> button.
If you wish, you may also enter a message that will be included
with the e-mail.
<P>
After sending the e-mail, you will automatically return to the
page you recommended.
</FONT>
<FORM METHOD="POST" ACTION="$SCRIPT_NAME">
<INPUT TYPE="HIDDEN" NAME="call_by" VALUE=$ENV{'HTTP_REFERER'}>
<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=0 >
<TR>
<TD> </TD>
<TD ALIGN=CENTER><B>Name</B></TD>
<TD ALIGN=CENTER><B>E-Mail Address</B><TD>
</TR>
<TR>
<TD><B>You</B></TD>
<TD><INPUT TYPE="TEXT" NAME="send_name"></TD>
<TD><INPUT TYPE="TEXT" NAME="send_email"></TD>
</TR>
__REQUEST__
for ($i=1;$i<$MAXNUM+1;$i++)
{
print <<__STOP_OF_ROW__;
<TR>
<TD><B>Friend $i</B></TD>
<TD><INPUT TYPE="TEXT" NAME="recipname_$i"></TD>
<TD><INPUT TYPE="TEXT" NAME="recipemail_$i"></TD>
</TR>
__STOP_OF_ROW__
}
print <<__REQUEST2__;
<TR>
<TD> </TD>
<TD ALIGN=CENTER COLSPAN=2>
<B>Your Message</B><BR>
<textarea name="message" wrap=virtual rows=5 cols=35></textarea>
<BR>
<P>
<INPUT TYPE="submit" VALUE="SEND">
</TD>
</TR>
</TABLE>
</FORM>
</BLOCKQUOTE>
<CENTER>
<FONT SIZE="-1">
</CENTER>
</TD>
</TR>
</TABLE>
__REQUEST2__
}
##################################################################
sub decode_vars
{
$i=0;
if ( $ENV{'REQUEST_METHOD'} eq "GET")
{
$temp=$ENV{'QUERY_STRING'};
}
else
{
read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
}
@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split(/=/,$item,2);
$content=~tr/+/ /;
$content=~s/%(..)/pack("c",hex($1))/ge;
$content=~s/\012//gs;
$content=~s/\015/ /gs;
$fields{$key}=$content;
}
if ($fields{'call_by'} eq "")
{
$JUMP_TO = $ENV{'HTTP_REFERER'};
}
else
{
$JUMP_TO = $fields{'call_by'};
}
}
##################################################################
sub valid_address
{
$testmail = $fields{$recipemail};
if ($testmail =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ | |
$testmail !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
{
return 0;
}
else
{
return 1;
}
}
sub valid_page
{
if (@okaydomains == 0) {return;}
$DOMAIN_OK=0;
$RF=$ENV{'HTTP_REFERER'};
$RF=~tr/A-Z/a-z/;
foreach $ts (@okaydomains)
{
if ($RF =~ /$ts/)
{ $DOMAIN_OK=1; }
}
if ( $DOMAIN_OK == 0)
{ print "Content-type: text/html\n\n Sorry, we can't run the script from here....";
exit;
}
}
##################################################################
sub test_sendmail
{
@ts=split(/ /,$MAIL_PROGRAM);
if ( -e $ts[0] )
{
return;
}
print "Content-type: text/html\n\n";
print "<H2>$ts[0] NOTFOUND. PLEASE CHECK YOUR SCRIPT'S MAIL_PROGRAM VARIABLE</H2>";
exit;
}
sub do_log
{
open (ZL,">>$LOGFILE");
$date=localtime(time);
for ($i=1;$i<$MAXNUM+1;$i++)
{
$recipname="recipname_$i";
$recipemail="recipemail_$i";
if ($fields{$recipemail} eq "")
{
next;
}
if (&valid_address == 0)
{
next;
}
$logline="$date\|$JUMP_TO\|$fields{'send_email'}\|$fields{$recipemail}\|\n";
print ZL $logline;
}
close(ZL);
}
###################################################################
sub sendmail {
my ($fromaddr
Anonymous posted this at 15:30 — 25th February 2000.
They have: 5,633 posts
Joined: Jan 1970
Orpheus posted this at 05:22 — 27th February 2000.
They have: 568 posts
Joined: Nov 1999
umm... this is kinda hard to ask but what is a BCC?
agates posted this at 13:03 — 27th February 2000.
They have: 6 posts
Joined: Feb 2000
blind carbon copy
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.