Gossamer Forum
Home : Products : DBMan : Customization :

"Email This" Option

(Page 1 of 2)
> >
Quote Reply
"Email This" Option
Hi There, JP!

I told you we'ld come up with some more challenging ideas for you. How about this one:

Our old database (which was sorely limited in most other areas) had one feature we'ld like to see with DBman. That is an option for a default user to choose to send a copy of any one post via email either to themselves or to a 3rd party.

I took a peak at the source code from our old database and found this:

<a href="forward.asp?webtag=reciperequests&msg=2587.1" target=_parent onMouseOver="window.status='Send above Message via Email';return true;">
<img height=13 width=26 src="/i/mb/forward_icon.gif" border=0 align=absbottom alt="Send above Message via Email">E-mail this</a>

Notice that it uses the record number to identify the record to send. This brings up another question. Our new database is quickly approaching 1500 records. If we search for record number "4" every instance of "4" in a record number is returned, not just the one record number "4."

Can this be improved? Will it affect any attempt to impliment the Email feature we want? Got any suggestions or ideas?

Thanks again,
BB



------------------
BigBritchs
BigBritchs@IDunno4Recipes.com



[This message has been edited by BigBritchs (edited June 27, 1999).]
Quote Reply
Re: "Email This" Option In reply to
(The cookies are all gone. Mmmmmmmmmmmm!) Smile

We can make a "Send this record" subroutine for DBMan. That's not too hard. Would you want the form where the user enters the recipient's email address to be directly on the record or would you want them to click a link (or button) and go to another form to enter the email address?

Regarding the key value -- if we use the get_record subroutine, it will look for the whole number. So if you use the command

&get_record("4");

you'll just get record 4 and not record 14 or 40. Another way to do this, if you are looking for a particular record is to add the "&ww=1" flag, which means "whole words." That, too, will only give you record 4, and not 14 or 40.

I'll be glad to help you with the "Mail this record" mod. Just let me know where you want the form, 'cause it makes a difference in the coding.


------------------
JPD





Quote Reply
Re: "Email This" Option In reply to
Rather than creating a sub-routine, you may want to consider using the Birdcast.cgi (recommend script) from

www.bignosebird.com/cgi.shtml .

Bobsie has written a great mod for using this script with LINKS and it would surely work with DBMAN (with a little extra tweaking). HIs mod is located at the following web page:

http://www.orphanage.com/...f/recommend_mod.html

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: "Email This" Option In reply to
Hi Eliot!

Thanks for the suggestion. I will certainly look into it. We currently use a BNB script for our "Tell-A-Friend" Site referral, so I am somewhat familiar with them and found that script to be relatively easy to work with.

As far as "tweeking" however, I am still quite green! JPDeni has helped me quite a bit and so has looking around some of the other posts on this forum.

Thanks again,
BB

------------------
BigBritchs
BigBritchs@IDunno4Recipes.com
http://www.IDunno4Recipes.com





[This message has been edited by BigBritchs (edited June 28, 1999).]
Quote Reply
Re: "Email This" Option In reply to
Hi JP!

Sorry to hear those cookies are gone already Frown

I think we would want a button on the same line as the "Main Menu/Search/List ALL/Home" in the footer. A user could choose it, enter both sender and receiver email addys, choose "Send" and then be returned to the original page.

Now this gets weired. We know there are some out there who have email access but do not have internet access. We would like to have the 2nd party return to our site to view the recipe and hopefully come back again and again. BUT, if the recipient doesn't have internet access, we would want them to at least get the recipe that was sent to them.

Is there a way for the browser to "know" the difference and send only a link back to our site for the recipe that was sent, but "know" when an email addy is not capable of using a link, and so "knowing" send the entire recipe? Are we reaching for the moon on this one?

Otherwise, I guess we'll want to send both the recipe requested by the sender AND a link back to our site.

Regarding the key value issue, I assumed from what you said that a user searching for a particular recipe by its ID # would have to choose the "Whole Words" Search Option and made a comment to that effect on our search page.

Thanks,
BB



------------------
BigBritchs
BigBritchs@IDunno4Recipes.com
http://www.IDunno4Recipes.com



Quote Reply
Re: "Email This" Option In reply to
(I sure enjoyed them cookies while they were here!! Smile )

I'm gonna have to get back to you on this. I really just came on to see if there were some quick questions I could answer. This one will be a little long and I have some pressing business to attend to. I will get to it tomorrow, though.


------------------
JPD





Quote Reply
Re: "Email This" Option In reply to
I think I have it. Smile

There is no way to tell from an email address whether the person has web access or not -- at least as far as I know.

You are correct. You might need to tell folks that, if they have a specific recipe number they are looking for, they will need to check the "whole word" box on the search form.

Okay. I think this should work. I haven't tested it, except for syntax errors.

The link to email the record can't be within the html_footer. It will have to be within your html_record_long subroutine. That's the only way the script will know which record it needs to get.

In html_record_long, probably at the bottom of the display, add

print qq|<a href="$db_script_link_url&send_record_form=1&$db_key=$rec{$db_key}">Email this recipe to a friend</a>|;

Add two new subroutines to html.pl:

Code:
sub html_send_record_form {
# --------------------------------------------------------

my ($message) = $_[0];

$page_title = "Send a Recipe to a Friend";
&html_page_top;

$submit_button = "Send Recipe";
$reset_button = "Reset Form";

$auth_modify_own=0;
%rec=&get_record($in{$db_key});

# < -- Start page text -- >
print qq|
[Put whatever you want as introductory text here. If you want to use anything from the record,
use the $rec{'FieldName'} variables.
|;
# < -- End page text -->

if ($message) {
print qq|<$font>There were problems with sending your email message: $message</font>|;
}

print qq|
<form action="$db_script_url" method="POST" name="form1">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<input type=hidden name="$db_key" value="$rec{$db_key}">
<table>
<tr><td><$font>Your email address:</font></td>
<td><input type="text" name="sender_email" value="$in{'sender_email'}" size="40"></td></tr>
<tr><td><$font>The recipient's email address:</font></td>
<td><input type="text" name="recip_email" value="$in{'recip_email'}" size="40"></td></tr>
<tr><td colspan=2>
<p><center>
<INPUT TYPE="SUBMIT" NAME="send_record" VALUE="$submit_button">
<INPUT TYPE="RESET" VALUE="$reset_button">
</center></p></td></tr></table></form>
|;

&html_footer;
&html_page_bottom;
}

sub html_send_record_success {
# --------------------------------------------------------

my ($message) = $_[0];

$page_title = "Recipe has been sent";
&html_page_top;

# < -- Start page text -- >
print qq|
<$font>The recipe has been sent to $message.</font>
|;
# < -- End page text -->

&html_footer;
&html_page_bottom;
}

Add the following to your .cfg file, if it's not already there

# Email program on your system
$mailprog = "|/usr/sbin/sendmail -t -oeq";

Add the following lines to db.cgi, sub main, somewhere with the other "elsif" statements

Code:
elsif ($in{'send_record_form'}) { if ($per_view) { &html_send_record_form; } else { &html_unauth; } }
elsif ($in{'send_record'}) { if ($per_view) { &send_record; } else { &html_unauth; } }

Add the following new subroutine to db.cgi

Code:
sub send_record {
# --------------------------------------------------------

my ($message,$mailtext);

if ($in{'sender_email'}) {
unless ($in{'sender_email'} =~ /.+\@.+\..+/) {
$message = "Your email address is not in the correct format.<BR>";
}
}
else {
$message = "You must enter your email address.<BR>";
}
if ($in{'recip_email'}) {
unless ($in{'recip_email'} =~ /.+\@.+\..+/) {
$message = "The recipient's email address is not in the correct format.<BR>";
}
}
else {
$message = "You must enter the recipient's email address.<BR>";
}

if ($message) {
&html_send_record_form($message);
return;
}
$auth_modify_own = 0;
%rec = &get_record($in{$db_key});

$mailtext = qq|[format the output of the email message here, using the $rec{'FieldName'} variables.
Use \n wherever you would like a new line to appear. You can also just use separate lines within
the text of the message and they will appear as separate lines within the email message.|;

open (MAIL, "$mailprog") or &cgierr("Can't start mail program");
print MAIL "To: $in{'recip_email'}\n";
print MAIL "From: $in{'sender_email'}\n";
print MAIL "Subject: Recipe from $html_title\n\n";
print MAIL $mailtext;
close MAIL;

&html_send_record_success($in{'recip_email'});
}

That should do it. Let me know if it isn't what you had in mind.



------------------
JPD





Quote Reply
Re: "Email This" Option In reply to
It doesn't matter where you place the subroutines, so long as they're not in the middle of another subroutine. Smile



------------------
JPD





Quote Reply
Re: "Email This" Option In reply to
Hi JP!

This looks like it otta work (like I would know!). Anyway, I'll give it a try ASAP.

One question: does it matter where in any particular file I put the new codes or will anywhere do? Just trying to anticipate glitches before I cause them.

Thanks again,
BB


------------------
BigBritchs
BigBritchs@IDunno4Recipes.com
http://www.IDunno4Recipes.com



Quote Reply
Re: "Email This" Option In reply to
Thanks JP!

I am going to give it a shot right now!

BB


------------------
BigBritchs
BigBritchs@IDunno4Recipes.com
http://www.IDunno4Recipes.com



Quote Reply
Re: "Email This" Option In reply to
I'll be looking forward to hearing how it works. (It's sure nice to have all these guinea pigs for my new code!! Wink )

I'll be checking in later. I gotta go make dinner.



------------------
JPD





Quote Reply
Re: "Email This" Option In reply to
Hi JP!

Well, I put it in as best I could, but I'm not seeing anything when I try it. Following your instructions I put the following code at the end of the html_record_long subroutine after the table and before the End of Record Display "}" tag. Should it go after the "}"?

</TABLE>
|;

print qq| <a href="$db_script_link_url&send_record_form=1&$db_key=$rec{$db_key}">Email this recipe to a friend</a> |;

# <-- End of record display -->

}


So far the changes haven't caused any probelms with normal operations, I just can't see the command to test it.

Waddaya Tink?

BB


------------------
BigBritchs
BigBritchs@IDunno4Recipes.com
http://www.IDunno4Recipes.com





[This message has been edited by BigBritchs (edited June 29, 1999).]
Quote Reply
Re: "Email This" Option In reply to
That's where it should go. I may have to take a look myself to see what's up. Can you make your html.pl script available on the web for me?


------------------
JPD





Quote Reply
Re: "Email This" Option In reply to
Hi JP!

Sorry about that. I was working with a set of backed up files so I wouldn't do any irreversable damage and never copied them over to the working cgi-bin folder. DUMB!

I copied the files over to the right folder and gave it a go. The "E Mail This Recipe to a Friend" shows up on the record, but I get an error message that reads "Error: Unknown Action - The database program received a command it did not understand."

I put all the relevant files in a new folder at:

http://www.IDunno4Recipes.com/emailop

Let me know if you can see what I missed.

Thanks,
BB

------------------
BigBritchs
BigBritchs@IDunno4Recipes.com
http://www.IDunno4Recipes.com





[This message has been edited by BigBritchs (edited June 30, 1999).]

[This message has been edited by BigBritchs (edited June 30, 1999).]
Quote Reply
Re: "Email This" Option In reply to
Your URL wouldn't let me see the directory listing, but I was able to download the db.cgi script.

I guess I wasn't clear about where to put:

Code:
elsif ($in{'send_record_form'}) { if ($per_view) { &html_send_record_form; } else { &html_unauth; } }
elsif ($in{'send_record'}) { if ($per_view) { &send_record; } else { &html_unauth; } }

Move that code to somewhere in the list of "elsif" statements further up in db.cgi, around the place where

Code:
elsif ($in{'add_record'}) { if ($per_add) { &add_record; } else { &html_unauth; } }
elsif ($in{'view_search'}) { if ($per_view) { &html_view_search; } else { &html_unauth; } }

is. It needs to be in that section.

When you asked about where to put the code, I was just thinking about the subroutines. Sorry 'bout that.


------------------
JPD





Quote Reply
Re: "Email This" Option In reply to
Hi JP!

Yeppers, I did put those lines in the wrong place. I followed your instructions and all seems well, except one little thing....

I've sent numerous recipes to various addresses and even though the script says they were sent, I've not received any of them!

I have a feeling this is related to the problems we had installing BigNoseBird's script for user referrals to other email addys. In that scenario, we had to redirect the code as follows

# Use $SMTP_SERVER
# $SMTP_SERVER="localhost";
$SMTP_SERVER="smtp.securewebs.com";

So I tried:

# Email program on your system
# $mailprog = "|/usr/sbin/sendmail -t -oeq";
$mailprog = "smtp.securewebs.com";

and got a CGI ERROR message that I didn't get before, so I put it back the way it was.

Is this an issue we can work out or do I need to call my server admin and get him in on the deal?

Thanks again,
BB



------------------
BigBritchs
BigBritchs@IDunno4Recipes.com
http://www.IDunno4Recipes.com



Quote Reply
Re: "Email This" Option In reply to
It probably does have something to do with sendmail and the smtp server, but you have just gotten into an area I know nothing about. There's something in the Links script about a Mailer.pm module. I'll look over it tonight and see if I can figure out how to use it.

Or someone else might have experience with this and be able to answer. (Hint, hint! Smile )


------------------
JPD





Quote Reply
Re: "Email This" Option In reply to
Hi JP!

OK, I'll ask my server admin to take a look at it and let you know what he says.

Don't knock yourself out, ours is probably a somewhat unique sitch.

Thanks again,
BB

------------------
BigBritchs
BigBritchs@IDunno4Recipes.com
http://www.IDunno4Recipes.com



Quote Reply
Re: "Email This" Option In reply to
Hi there, I modfied everything as stated by JPDeni, but get a CGI error message :

fatal error: Undefined subroutine &main::html_page_top called at /home/..../html.pl line 1631

I guess html_top_page has to be defined as well but JPDeni didn't mention it ?

Thanks

Luke
Quote Reply
Re: "Email This" Option In reply to
Your page formatting may be a little different that the example provided above.

Remember when using coding written for others, that you have to modify the code to suit your individual database. For example field names provided may not match your field names Smile

In this case $html_page_top is used with the user friendly mod to define the page header.

For your database the page headers may be defined in: &html_print_headers;

Just make the necessary changes to match your page formatting and it should work just fine Smile



Quote Reply
Re: "Email This" Option In reply to
Yeah. You do need to understand that when I write code for folks on the forum, I often already know what sort of setup they have for their database. (I had worked with "BigBritchs" for qute a while when I wrote this.)



------------------
JPD





Quote Reply
Re: "Email This" Option In reply to
In the place of

&html_page_top

use

Code:
&html_print_headers;

print qq|
<html><head><title>$html_title: $page_title</title></head>
<body bgcolor="#DDDDDD">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF"><b>$html_title: $page_title</b></font></td></tr>
<tr><td><p><center><$font_title><b>$page_title</b></font></center><br>
|;

In the place of

&html_page_bottom

use

Code:
print qq|
<table border=0 width=100%>
<tr>
<td align=left><$font>Copyright 1998
<A HREF="http://www.gossamer-threads.com">Gossamer Threads Inc.</A></font></td>
<td align=right>
<a href="http://www.gossamer-threads.com/scripts/dbman/">
<img src="http://www.gossamer-threads.com/images/powered.gif"
border=0 width=100 height=31 alt="Database Powered by Gossamer Threads Inc."></a>
</td></tr>
</table>
|;

print qq|
</td></tr></table></center></body></html>
|;
}


------------------
JPD





Quote Reply
Re: "Email This" Option In reply to
Hi JPD. Thanks, that worked !!!!!!!
But I still have a problem : in db.cgi, the lines that say

"format the output of the email message here, using the $rec{'FieldName'} variables. Use \n wherever you would like a new line to appear. You can also just use separate lines within the text of the message and they will appear as separate lines within the email message.|;

, when I put a variable, like $rec{'FirstName'} , that spot appears blank in the test e-mail I receive.

Am I doing something wrong , or I don't know how to refer the variable in the text ?
Could you please give me an example ?

Thanks,

Luke

PS. Any idea what should be done so that sendmail sends the e-mail in html format not in plain text ( Content-type: text/plain vs. Content-type: text/html ) ?



[This message has been edited by lukebrenner (edited March 26, 2000).]
Quote Reply
Re: "Email This" Option In reply to
If your $rec{'FieldName'} variables are blank, there are two possible causes. One is that you aren't using the correct FieldName. These must be exactly the same as in the .cfg file, including capitalization.

If that's not the problem, then you are not getting the record returned from the

%rec = &get_record($in{$db_key});

line.

Try switching some things around. Instead of

Code:
if ($in{'recip_email'}) {
unless ($in{'recip_email'} =~ /.+\@.+\..+/) {
$message = "The recipient's email address is not in the correct format.<BR>";
}
}
else {
$message = "You must enter the recipient's email address.<BR>";
}
if ($message) {
&html_send_record_form($message);
return;
}
$auth_modify_own = 0;
%rec = &get_record($in{$db_key});

use

Code:
if ($in{'recip_email'}) {
unless ($in{'recip_email'} =~ /.+\@.+\..+/) {
$message = "The recipient's email address is not in the correct format.<BR>";
}
}
else {
$message = "You must enter the recipient's email address.<BR>";
}
%rec = &get_record($in{$db_key});
unless ($rec{$db_key}) {
$message = "No record was returned from the search";
}
if ($message) {
&html_send_record_form($message);
return;
}
$auth_modify_own = 0;

See what happens.


------------------
JPD







[This message has been edited by JPDeni (edited March 26, 2000).]
Quote Reply
Re: "Email This" Option In reply to
JPD, I get a CGI 500 error message when I try to access db.cgi.

I tried debugging int in the shell with perl -cw db.cgi and I get :



syntax error at db.cgi line 1189, near "$db_key) "
syntax error at db.cgi line 1210, near "}"



even though it doesn't seem to be a syntax error.

PS I forgot to mention :

1) I do not use the autogenerate function for the forms (designed them myself)
2) I use the right syntax for the fieldnames . Ex : I have a fieldname called EXACTLY like that : FirstName

[This message has been edited by lukebrenner (edited March 26, 2000).]
> >