Gossamer Forum
Home : Products : Links 2.0 : Customization :

recommend it modification, mail wont send

Quote Reply
recommend it modification, mail wont send
see code below for reference.. sorry i am pasting the entire birdcast.cgi file.

Code:
#!/usr/bin/perl
use Socket;
require "/usr/local/etc/httpd/htdocs/tylertx/links/cgi/admin/links.cfg";
require "$db_script_path/links.def";
require "$db_script_path/db_utils.pl";
$|=1;
##################################################################
# birdcast.cgi Version 2.0
# updated May 2, 1999
# (C)1998, 1999 Bignosebird.com
# This software is FREEWARE! Do with it as you wish. It is yours
# to share and enjoy. Modify it, improve it, and have fun with it!
# It is distributed strictly as a learning aid and bignosebird.com
# disclaims all warranties- including but not limited to:
# fitness for a particular purpose, merchantability, loss of
# business, harm to your system, etc... ALWAYS BACK UP YOUR
# SYSTEM BEFORE INSTALLING ANY SCRIPT OR PROGRAM FROM ANY
# SOURCE!
##################################################################

# CONFIGURATION NOTES

#
# $SCRIPT_NAME is the full URL of this script, including the
# http part, ie, "http://domainname.com/cgi-bin/birdcast.cgi";
#
# $SITE_NAME is the "name" of your web site.
# $SITE_URL is the URL of your site (highest level)
# $END_LINE is the very last line printed in the e-mail.
#
# $MAXNUM is the number of possible people a person can refer
# your URL to at one time. If you call the script using the
# GET method, then this is also the number of entry blanks
# created for recipient names and addresses.
#
# $SMTP_SERVER is the name of your e-mail gateway server, or
# SMTP host. On most systems, "localhost" will work just fine.
# If not, change "localhost" to whatever your ISP's SMTP
# server name is, ie, smtp.isp.net or mail.isp.net

# $SEND_MAIL is the full path to your server's sendmail program
# If you do not wish to use Sockets for some reason and need
# to use sendmail, uncomment the $SEND_MAIL line and comment
# the $SMTP_SERVER line.

# okaydomains is a list of domains from which you want to allow
# the script to be called from. Leave it commented to leave the
# script unrestricted. If you choose to use it, be sure to list
# your site URL with and without the www.

# Use either $SMTP_SERVER
# $SMTP_SERVER="tylersites.com";
#
# OR
#
$SEND_MAIL="/usr/bin/sendmail";
#
# BUT NEVER BOTH!!!!!!

# @okaydomains=("http://www.etexonline.com", "http://etexonline.com");

$SCRIPT_NAME="http://www.tylertx.net/links/cgi/birdcast.cgi";
$SITE_NAME="East Texas Online";
$SITE_URL="http://www.tylertx.net/links/";
$ENDLINE="";
$MAXNUM=5;
$LOGFILE="reflog.txt";

if ($SENDMAIL ne "")
{&test_sendmail;}


&valid_page; #if script is called from offsite, bounce it!
&decode_vars;
%rec = &get_record($fields{'ID'});
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;
}

#BNB SAYS! You can modify the Subject line below.
my $carbon = "Bcc: pres\@tylersites.com";
$subject = "Web Page Recommendation from $fields{'send_name'}";

#BNB SAYS! Modify the lines below between the lines marked
# with __STOP_OF_MAIL__ to customize your e-mail message
# DO NOT remove the lines that contain __STOP_OF_MAIL__!
# If you enter any hardcoded e-mail addresses, BE SURE TO
# put the backslash before the at sign, ie, me\@here.net

$msgtxt = <<__STOP_OF_MAIL__;
Hi $fields{$recipname},

$fields{'send_name'} stopped by $SITE_NAME
and suggested that you visit the following URL:

Site Name: $rec{'Title'}
Site Location: $rec{'URL'}
Site Description: $rec{'Description'}


__STOP_OF_MAIL__

if ($fields{'message'} ne "")
{
$msgtxt .= "Here is a personal message from $fields{'send_name'}....\n";
$msgtxt .= "--------------------------------------\n\n";
$msgtxt .= "$fields{'message'}\n\n";
$msgtxt .= "--------------------------------------\n\n";
}
$msgtxt .= "$SITE_NAME\n";
$msgtxt .= "$ENDLINE\n";
$msgtxt .= "$SITE_URL\n\n";
$mailresult = &sendmail(
$fields{send_email},
$fields{send_email},
$fields{$recipemail},
$SMTP_SERVER,
$subject,
$msgtxt,
$carbon
);

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";

#BNB SAYS! Here is the part that draws the page that asks the
#reader to enter e-mail addresses and names. Tailor it to meet
# your needs if necessary. DO NOT disturb the lines with
# __REQUEST__ on them.

print <<__REQUEST__;
<body bgcolor="#FFFFFF" alink="#0000BB" vlink="#0000BB" link="#0000BB">
<SCRIPT LANGUAGE="JavaScript">
<!--
ua=navigator.userAgent;
v=navigator.appVersion.substring(0,1);
if ((ua.lastIndexOf("MSIE")!=-1) && (v!='1') && (v!='2') && (v!='3')) {
document.body.onmouseover=makeCool;
document.body.onmouseout=makeNormal;
}
function makeCool() {
src = event.toElement;
if (src.tagName == "A") {
src.oldcol = src.style.color;
src.style.color = "red";
}
}
function makeNormal() {
src=event.fromElement;
if (src.tagName == "A") {
src.style.color = src.oldcol;
}
}
//-->
</SCRIPT>
<center>

<table border="0" cellpadding="0" cellspacing="0" width="600">
<tr>
<td colspan=2> <img src=http://www.tylertx.net/images/logo.gif alt="East Texas Online" width=600 height=60 border=0 usemap="#gnav">
</td>
</tr>
<tr bgcolor=#82C0FF>
<td nowrap> <font face=geneva,arial,helvetica size=-1><b> <a href="http://tylertx.net/links">Home</a>: Add URL </b></font> </td>
<td align=RIGHT nowrap><form method="get" action="http://www.tylertx.net/links/cgi/redirect.cgi" name="">
<select name="select" size="1">
<option value="http://www.tylertx.net/links/">Select Category</option>
<option value="http://www.tylertx.net/links/Arts_&_Humanties/">Arts & Humanties</option>
<option value="http://www.tylertx.net/links/Business_&_Money/">Business & Money</option>
<option value="http://www.tylertx.net/links/Computing_&_Internet/">Computing & Internet</option>
<option value="http://www.tylertx.net/links/Education/">Education</option>
<option value="http://www.tylertx.net/links/Entertainment/">Entertainment</option>
<option value="http://www.tylertx.net/links/Health/">Health</option>
<option value="http://www.tylertx.net/links/Kids_&_Family/">Kids & Family</option>
<option value="http://www.tylertx.net/links/Living/">Living</option>
<option value="http://www.tylertx.net/links/Local/">Local</option>
<option value="http://www.tylertx.net/links/News_&_Media/">News & Media</option>
<option value="http://www.tylertx.net/links/Oddities/">Oddities</option>
<option value="http://www.tylertx.net/links/People_&_Society/">People & Society</option>
<option value="http://www.tylertx.net/links/Science_&_Technology/">Science & Technology</option>
<option value="http://www.tylertx.net/links/Shopping/">Shopping</option>
<option value="http://www.tylertx.net/links/Sports_&_Leisure/">Sports & Leisure</option>
<option value="http://www.tylertx.net/links/Travel/">Travel</option>
</select>

<input type="submit" value="GO!" >
</td>

</tr>
</form>

</table>

<br>

Place Banner Here<br>

<br>

<table width=600 border=0 cellpadding=1 cellspacing=0>

<tr>

<td> <font face=arial,helvetica size=+1 color=000000><b> Recommend a Site to a Friend</b></font></td>

</tr>

<tr>

<td bgcolor=ff0000><img src=/img/web/hdr/spacer.gif width=100% height=1></td>

</tr>

<tr>

<td>  </td>

</tr>

</table>

<p>
<table width=600 cellpadding=2 cellspacing=0 border=1>
<tr>



<td valign=top height="529" width="100%">
<table>
<tr>
<td>
<table border=0 cellspacing=0 cellpadding=4 width=100%>
<tr>
<td><font face=geneva,helvetica size=-1>SUGGEST THIS SITE TO A FRIEND...<P>
<b> $rec{'Title'}<br></b>
$rec{'Description'}<p>
</CENTER>
</B>
</FONT>
<FONT FACE="Geneva, Helvetica" SIZE=2 COLOR="#000000">
If you have a friend that you would like to recommend this site to,
or if you just want to send yourself a reminder, here is the easy
way to do it!
<P>
Simply fill in the e-mail address of the person(s) you wish to tell
about $SITE_NAME, your name and e-mail address (so they do
not think it is spam or reply to us with gracious thanks),
and click the <B>SEND</B> button.
If you want to, you can also enter a message that will be included
on the e-mail.
<P>
After sending the e-mail, you will be transported back to the
page you came from!
</FONT>
<FORM METHOD="POST" ACTION="$SCRIPT_NAME">
<INPUT TYPE="HIDDEN" NAME="call_by" VALUE=$ENV{'HTTP_REFERER'}>
<input type="hidden" name="ID" value="$rec{'ID'}">
<TABLE WIDTH=100% BORDER=0 CELLPADDING=1 CELLSPACING=0 >
<TR>
<TD bgcolor=#82C0FF> </TD>
<TD ALIGN=CENTER bgcolor=#82C0FF><B>Name</B></TD>
<TD ALIGN=CENTER bgcolor=#82C0FF><B>E-Mail Address</B><TD>
</TR>
<TR>
<TD bgcolor=#CEE7FF><B>You</B></TD>
<TD align="center" bgcolor=#CEE7FF><INPUT TYPE="TEXT" NAME="send_name"></TD>
<TD align="center" bgcolor=#CEE7FF><INPUT TYPE="TEXT" NAME="send_email"></TD>
</TR>
__REQUEST__
for ($i=1;$i<$MAXNUM+1;$i++)
{
print <<__STOP_OF_ROW__;
<TR>
<TD bgcolor=#CEE7FF><B>Friend $i</B></TD>
<TD align="center" bgcolor=#CEE7FF><INPUT TYPE="TEXT" NAME="recipname_$i"></TD>
<TD align="center" bgcolor=#CEE7FF><INPUT TYPE="TEXT" NAME="recipemail_$i"></TD>
</TR>
__STOP_OF_ROW__
}
print <<__REQUEST2__;
<TR>
<TD bgcolor=#CEE7FF> </TD>
<TD bgcolor=#CEE7FF ALIGN=LEFT COLSPAN=2>
<B>Your Message</B><BR>
<textarea name="message" wrap=virtual rows=5 cols=30></textarea>
<BR>
<INPUT TYPE="submit" VALUE="SEND">
</TD>
</TR>
</TABLE>
</FORM>
</BLOCKQUOTE>
</TD>
</TR>
</TABLE>
<tr align=center bgcolor=ffffff>
<td colspan=2 height="2"> </td>
</tr>
</table>
</td>
</tr>
</table>
 <br>
<hr width=600 size=1 noshade>

<font face="Arial" size="2"><b><a href="<%build_root_url%>">Home</a> |

Add a Site | <a class="menulink" href="<%db_cgi_url%>/modify.cgi">Modify a Site</a>

| <a class="menulink" href="<%build_root_url%>/New">What's New</a> | <a class="menulink" href="<%build_root_url%>/Cool">What's

Cool</a> | <a class="menulink" href="<%db_cgi_url%>/search.cgi">Search</a></b></font><font face=geneva,arial size=-1>

</font><br>

<font face=tahoma,Arial,Helvetica color=#000000 size=-2> 

© 1999 </font><font face="tahoma,Arial,Helvetica" size="-2"><A HREF="http://www.tylersites.com" NAME="TylerSites Interactive" TARGET="new">TylerSites</A></font>

</center>

</body>

__REQUEST2__
}

##################################################################
# NOTHING TO MESS WITH BEYOND THIS POINT!!!!
##################################################################
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, cant run it 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
{
(-e $LOGFILE) ?
open (ZL,">>$LOGFILE") :
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);
}

###################################################################
#Sendmail.pm routine below by Milivoj Ivkovic
###################################################################
sub sendmail {

# error codes below for those who bother to check result codes <gr>

# 1 success
# -1 $smtphost unknown
# -2 socket() failed
# -3 connect() failed
# -4 service not available
# -5 unspecified communication error
# -6 local user $to unknown on host $smtp
# -7 transmission of message failed
# -8 argument $to empty
#
# Sample call:
#
# &sendmail($from, $reply, $to, $smtp, $subject, $message );
#
# Note that there are several commands for cleaning up possible bad inputs - if you
# are hard coding things from a library file, so of those are unnecesssary
#

my ($fromaddr, $replyaddr, $to, $smtp, $subject, $message, $carbon) = @_;

$to =~ s/[ \t]+/, /g; # pack spaces and add comma
$fromaddr =~ s/.*<([^\s]*?)>/$1/; # get from email address
$replyaddr =~ s/.*<([^\s]*?)>/$1/; # get reply email address
$replyaddr =~ s/^([^\s]+).*/$1/; # use first address
$message =~ s/^\./\.\./gm; # handle . as first character
$message =~ s/\r\n/\n/g; # handle line ending
$message =~ s/\n/\r\n/g;
$smtp =~ s/^\s+//g; # remove spaces around $smtp
$smtp =~ s/\s+$//g;

if (!$to)
{
return(-8);
}

if ($SMTP_SERVER ne "")
{
my($proto) = (getprotobyname('tcp'))[2];
my($port) = (getservbyname('smtp', 'tcp'))[2];

my($smtpaddr) = ($smtp =~
/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
? pack('C4',$1,$2,$3,$4)
: (gethostbyname($smtp))[4];

if (!defined($smtpaddr))
{
return(-1);
}

if (!socket(MAIL, AF_INET, SOCK_STREAM, $proto))
{
return(-2);
}

if (!connect(MAIL, pack('Sna4x8', AF_INET, $port, $smtpaddr)))
{
return(-3);
}

my($oldfh) = select(MAIL);
$| = 1;
select($oldfh);

$_ = <MAIL>;
if (/^[45]/)
{
close(MAIL);
return(-4);
}

print MAIL "helo $SMTP_SERVER\r\n";
$_ = <MAIL>;
if (/^[45]/)
{
close(MAIL);
return(-5);
}

print MAIL "mail from: <$fromaddr>\r\n";
$_ = <MAIL>;
if (/^[45]/)
{
close(MAIL);
return(-5);
}

foreach (split(/, /, $to))
{
print MAIL "rcpt to: <$_>\r\n";
$_ = <MAIL>;
if (/^[45]/)
{
close(MAIL);
return(-6);
}
}

print MAIL "data\r\n";
$_ = <MAIL>;
if (/^[45]/)
{
close MAIL;
return(-5);
}

}

if ($SEND_MAIL ne "")
{
open (MAIL,"| $SEND_MAIL");
}

print MAIL "To: $to\n";
print MAIL "From: $fromaddr\n";
print MAIL "$carbon\n";
print MAIL "Reply-to: $replyaddr\n" if $replyaddr;
print MAIL "X-Mailer: Perl Powered Socket Mailer\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$message";
print MAIL "\n.\n";

if ($SMTP_SERVER ne "")
{
$_ = <MAIL>;
if (/^[45]/)
{
close(MAIL);
return(-7);
}

print MAIL "quit\r\n";
$_ = <MAIL>;
}

close(MAIL);
return(1);
}

I have set the SMTP server address correct and the path for SENDMAIL is correct. However when I use the script off of my links site. the redirect will work fine, and the txt file generated by birdcast.cgi is logging the correct information. However when I test this with my email to send to, nothing happens, no mail is sent.. Can anyone help on this one.. This is all i need to fix so I can officially launch our site and it is behind 5 days now.. I emailed bobsie directly as he wrote the script but I have not heard from him in days.. No offence to him as I know he is busy.. Just really need to put closure on this one.

thanks
James



[This message has been edited by pres (edited September 15, 1999).]
Quote Reply
Re: recommend it modification, mail wont send In reply to
Try adding -t to your sendmail variable:

Code:
$SEND_MAIL="/usr/bin/sendmail -t";

Hope this helps.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: recommend it modification, mail wont send In reply to
I added that variable -t

and it still is not working.. i am confused.. it should have worked..

any thoughts..??

thanks eliot..

james
Quote Reply
Re: recommend it modification, mail wont send In reply to
Possibly you have the wrong sendmail path?

Try this code instead:

Code:
$SEND_MAIL = "|/usr/local/bin/sendmail -t -oeq";

May be this will work. Make sure that your sendmail program path is correct. In telnet, type in the following command line:

Code:
which sendmail

This will tell you the path to your sendmail program.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: recommend it modification, mail wont send In reply to
not working still..

here is a line from the text file log generated by this script

Code:
Thu Sep 16 01:58:43 1999|http://tylertx.net/links/Business_%26_Money/Banking_%26_Finance/|pres@tylersites.com|award@whatisthis.com|
Code:

I am at a loss.. I wish bobsie could see this ..

Any thoughts.. this is getting tough.

James
Quote Reply
Re: recommend it modification, mail wont send In reply to
can someone give feedback on this one.. need bobsie or someone with experience with birdcast.cgi to look and give thoughts on why an email will not send.. but the reflog.txt file show information.

thanks

james
Quote Reply
Re: recommend it modification, mail wont send In reply to
pres,

Since the sendmail option does not seem to be working for you. Why don't you try the SMTP option. Just configure it to connect to your SMTP server via Sockets. Also, rem out (#) the Sendmail line. You need to use either Sendmail or SMTP.

Other than that, why don't you send Bobsie an email since he wrote the Mod.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: recommend it modification, mail wont send In reply to
still nothing..??? how weird.. i removed the SEND MAIL line.. and left only the SMTP lines...

i did send bobsie a mail with my birdcast script as an attachment and he has not responded.. that was almost 1 week ago.. help!!!!

james
Quote Reply
Re: recommend it modification, mail wont send In reply to
Hi,

I have another problem with recommend it mod
I'm getting this error message
----------------------
Internal Server Error
malformed header from script. Bad header=Can't find string terminator "

----------------------
and the error is this
----------------------
Can't find string terminator "__STOP_OF_MAIL__" anywhere before EOF
----------------------
which it is in this line of recommend.cgi
under sub process_mail
----------------------
$msgtxt = <<__STOP_OF_MAIL__;
Hi $fields{$recipname},

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

any one can help please.. Thanks

Quote Reply
Re: recommend it modification, mail wont send In reply to
if anyone here is using the recommend it MOD and is willing to release their own copy to me (i will make our own changes to fit our site) please let me know and send me and email with the .cgi attachment. maybe we can get it to work if it is working on your own site.

Thanks, we are seriously delayed in launching our own site due to this mod not working.

thanks

james
Quote Reply
Re: recommend it modification, mail wont send In reply to
i cant get mine to work either.
mine gives me a 500 error...

...
cant figure

..
got it to work...
now i just need to figure out how to
bcc a copy to myself....

..
Work Perfectly now....cool..

[This message has been edited by clubhead (edited September 23, 1999).]

[This message has been edited by clubhead (edited September 23, 1999).]
Quote Reply
Re: recommend it modification, mail wont send In reply to
pres,

Code:
Hi $fields{$recipname},
$fields{'send_name'} stopped by $SITE_NAME
and suggested that you visit the following URL:
Site Name: $rec{'Title'}
Site Location: $rec{'URL'}
Site Description: $rec{'Description'}
__STOP_OF_MAIL__

I hope this helps.
Quote Reply
Re: recommend it modification, mail wont send In reply to
thanks bobsie

let me kmow what you find out.

thanks

james