Gossamer Forum
Home : Products : DBMan : Customization :

emailthis mod....wanna push it further..

Quote Reply
emailthis mod....wanna push it further..
Hi all,

the emailthis mod is great!! and i was wondering if anyone can push it a little bit further....can you, actaully include the html document within ur email? like instead of printing out the variables and sent it as a plan plan plan email
can we including the pic ( i have got upload mod installed)
as an attachment and set all the variables in a table as an html document???

thanks in advance!!


Quote Reply
Re: emailthis mod....wanna push it further.. In reply to
HTML formats in email messages have been covered in the CGI/Perl Forum in this site.

For attachments, it is possible...but would take a bit of work to get it working. Also, your sendmail or SMTP server must be configured correctly to attach files from Perl based mail forms.

Regards,

Eliot Lee
Quote Reply
Re: emailthis mod....wanna push it further.. In reply to
I have a plain database for testing SMTP emails with pics at the following url. http://www.fastcom.uk.com/cgi-bin/shop/test/db.cgi?db=bookstore

It gives the user the choice of sending the record with or without pic. The mod is adapted from the Forward Record mod by JP. Record 1038 has the picture deliberately missing(the email sends a different message).
If you like it I will post the url for the code.

I don't use the upload mod, but if it just stores the image name in the database the code should run as is, otherwise it will need a reg exp.

HTML can be inserted in the textarea provided you use
opening and closing tags
<html>
<head>
</head>
<body>
field 0 from database
field 1 etc
</body>
</html>
The mod could be modified again to either default to HTML or give the user the choice, but the HTML tags would be displayed in the text area.

rog


Quote Reply
Re: emailthis mod....wanna push it further.. In reply to
Thanks rog and Eliot...

rog would you please show me the code??
thanks..
I will look into the tutorial and come back with more questions....


thanks




Quote Reply
Re: emailthis mod....wanna push it further.. In reply to
 
This has been tested on Unix servers and works from my win98 machine, so I don't see any reason why it should not work with NT or others.

http://www.fastcom.uk.com/dbman/forward_record_withimages.txt

rog


Quote Reply
Re: emailthis mod....wanna push it further.. In reply to
Thanks rog!!
will report back with the latest progress sooon!!
:)

Quote Reply
Re: emailthis mod....wanna push it further.. In reply to
rog:
how do i add my html page in it?? let's say i want to include my message and the image in a html document, how do i do that?? and will it work both on outlook type or hotmail type??
cheers,

Paul

Quote Reply
Re: emailthis mod....wanna push it further.. In reply to
Did the code work alright for you?

We will create an extra form for the HTML email.
In your .cfg file you need (and you will probably have something like)

$UPLOADURL = "http://www.yourdomain/upimages";
$ALLOWED_EXT = '\.gif$|\.jpg$';

In db.cgi in sub main add this line with all other elseif's

elsif ($in{'forward_email_htmlform'}) { if ($per_view) { &html_forward_email_htmlform; }else { &html_unauth; } }

In html.pl add this subroutine

sub html_forward_email_htmlform {
#----------------------------------------------------------
my ($message) = $_[0];
$in{$db_key} =~ s/<?.B>//g;
$auth_modify_own = 0;
%rec = &get_record($in{$db_key});

unless ($in{'emailmessage'}) {
foreach $col (@db_cols) {
$rec{$col} =~ s/\n/
/g;
if ($rec{$col} =~ /$ALLOWED_EXT/){ $rec{$col} = "<img src= $UPLOADURL/$rec{'Image Name'}>";}
$in{'emailmessage'} .= "<tr><td align=right><$font>$col:</font></td><td><$font>$rec{$col}</font></td></tr>\n";
}
}
&html_print_headers;

print qq|
<html><head><title>$html_title: Send an email</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: Send an email</b></td></tr>
<tr><td>
<p><center><$font_title><b>
Send an email
</b></font></center>

|;

if ($message) { print qq|There was a problem: $message|; }
print qq|
<$font>Fill in your email address, the subject of your email and the
message you wish to send to .</font>
|;

print qq|
<FORM action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<input type=hidden name="$db_key" value="$in{$db_key}">
<table><tr><td align=right><$font>Your email address:</font></td>
<td><input type=text name="email" value="$in{'email'}" size=40></td></tr>
<tr><td align=right><$font>Recipient's email address:</font></td>
<td><input type=text name="to_email" value="$in{'to_email'}" size=40></td></tr>
<tr><td align=right><$font></font></td><td><$font>To send to more than one email address seperate
with a comma (eg. email\@hisdomain.com, email\@herdomain.com)</font></td></tr>
<tr><td align=right><$font>Subject:</font></td>
<td><input type=text name="subject" value="$in{'subject'}" size=40></td></tr>
<tr><td align=right><$font></font></td>
<td><input type=hidden name="Image Name" value="" size=40><$font></font></td></tr>
<tr><td align=right><$font>This record :</font></td>
<td><textarea name="emailmessage" cols=40 rows=10 readonly="readonly" wrap="virtual"><html><head></head><body><TABLE WIDTH="450" CELLPADDING=0 CELLSPACING=0 BORDER=1 BGCOLOR="#FFFFCC">
$in{'emailmessage'}</body>
</html></TEXTAREA></td></tr>
</table>
<center>
<INPUT TYPE="SUBMIT" NAME="forward_email" VALUE="Send Record">
<INPUT TYPE="RESET" VALUE="Reset Form">
</center>
</form>
|;
&html_footer;
print qq|</td></tr></table></body></html>|;
}


I have made the textarea readonly but you can remove that.

More than one email can be sent at a time if they are seperated by a comma, the same applies to the plain email.

At the bottom of sub html record you will need something similar to

<a href="$db_script_link_url&$db_key=$rec{$db_key}&forward_email_form=1"><$font>Send this record to a friend</Font></a><br />
<a href="$db_script_link_url&$db_key=$rec{$db_key}&forward_email_htmlform=1"><$font>Send this record to a friend as HTML</Font></a>

The HTML comes through as one whole page to Eudora 4.3, I don't use Outlook or Hotmail, but can you let me know if it is ok.

rog



Quote Reply
Re: emailthis mod....wanna push it further.. In reply to
thank you rog,

well all the info got printed out but not the image.... :(

well i kinda figure out why......

with my upload mod, once u have upload the file it automatically chnage the filename into ur user name, for e.g
if ur image name is call "me.jpg" and ur userid is "hello"
it will rename the file into "hello.jpg" rather then me.jpg
and it accepts jpg and gif

and on the default.db, it actually stores the local path of the user rather where exactly the image is located..so on my deafault db it will write something like "C:\WINDOWS\Desktop\me.jpg" and on the email it will just print out "Filename: C:\WINDOWS\Desktop\me.jpg" Where Filename is the field name for image

...

sorry to bug u again.... and thanks!

Paul

Quote Reply
Re: emailthis mod....wanna push it further.. In reply to
Hello token,
Some formatting did not come through right on the post,
under: foreach $col (@db_cols) {
the next line should read
Code:
$rec{$col} =~ s/\n/<BR>/g;
.

Which date is your upload mod dated?
You should also be seeing at least some http:// somewhere in the email.

Is your $UPLOADURL = "http:// or $SAVE_DIRECTORY_URL = "http:/ properly defined in the html.pl, ie "<img src= $UPLOADURL/$rec etc?

rog


Quote Reply
Re: emailthis mod....wanna push it further.. In reply to
hi rog,

the html works out fine in hotmail but not outlook...and i dont know why...i have a script which aloud you to send e-card as an html format, would you like a copy of it? perhaps there is something useful...

and regarding to the save url i am acutally using $SAVE_DIRECTORY_URL

here is what i got for the code:

sub html_forward_email_htmlform {
#----------------------------------------------------------
my ($message) = $_[0];
$in{$db_key} =~ s/<?.B>//g;
$auth_modify_own = 0;
%rec = &get_record($in{$db_key});

unless ($in{'emailmessage'}) {
#foreach $col (@db_cols) {
$rec{$col} =~ s/\n//g;

if ($rec{$col} =~ /$ALLOWED_EXT/){ $rec{$col} = "<img src= $UPLOADURL/$rec{'userid'}>";}
$in{'emailmessage'} .= "<tr><td>$rec{$col}$email_info\n</td></tr>";
#}
}
&html_print_headers;

print qq|
<html><head><title>$html_title: Send an email</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: Send an email</b></td></tr>
<tr><td>
<p><center><$font_title><b>
Send an email
</b></font></center>

|;

if ($message) { print qq|There was a problem: $message|; }
print qq|
<$font>Fill in your email address, the subject of your email and the
message you wish to send to .</font>
|;

print qq|
<FORM action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<input type=hidden name="$db_key" value="$in{$db_key}">
<table><tr><td align=right><$font>Your email address:</font></td>
<td><input type=text name="email" value="$in{'email'}" size=40></td></tr>
<tr><td align=right><$font>Recipient's email address:</font></td>
<td><input type=text name="to_email" value="$in{'to_email'}" size=40></td></tr>
<tr><td align=right><$font></font></td><td><$font>To send to more than one email address seperate
with a comma (eg. email\@hisdomain.com, email\@herdomain.com)</font></td></tr>
<tr><td align=right><$font>Subject:</font></td>
<td><input type=text name="subject" value="$in{'subject'}" size=40></td></tr>
<tr><td align=right><$font></font></td>
<td><input type=hidden name="Image Name" value="" size=40><$font></font></td></tr>
<tr><td align=right><$font>This record :</font></td>
<td><textarea name="emailmessage" cols=40 rows=10 readonly="readonly" wrap="virtual"><html><head></head><body><TABLE WIDTH="450" CELLPADDING=0 CELLSPACING=0 BORDER=1 BGCOLOR="#FFFFCC">
$in{'emailmessage'}</body>
</html></TEXTAREA></td></tr>
</table>
<center>
<INPUT TYPE="SUBMIT" NAME="forward_email" VALUE="Send Record">
<INPUT TYPE="RESET" VALUE="Reset Form">
</center>
</form>
|;
&html_footer;
print qq|</td></tr></table></body></html>|;
}

also, is this r elate to the sub forward_email in db.cgi???
if so, instead of $image_name , what sud i use instead? just the $userid? cos the upload mod renamed the file to the userid...



thanks!

i gues all i want now is just sending it as a html document....and perhaps attach with some graphics...not the users' upload image...
so in my $email_info, i can use $rec{'fieldname'} right?? do i then have to define my $email_info under the html.pl or deafault.cfg?


thanks!
Quote Reply
Re: emailthis mod....wanna push it further.. In reply to
Hello Paul,

Either email the script or post a url for it, cheers.
As per my previous post change $rec{$col} =~ after the foreach.

I take it you are using the email to send one record , the picture.

This is related to the sub forward_email routine in db.cgi,
replace any reference to 'Image Name' with your own IMAGE field not userid.

In your text above change "<img src= $UPLOADURL/$rec{'userid'}>";}

to "<img src= $SAVE_DIRECTORY_URL/$rec{'yourimagefield'}>";}


and change

<td><input type=hidden name="Image Name" value="" size=40><$font></font></td></tr>

to
<td><input type=hidden name="Your Image Field" value="" size=40><$font></font></td></tr>

I have put a closing table tag in this line
><TABLE WIDTH="450" CELLPADDING=0 CELLSPACING=0 BORDER=1 BGCOLOR="#FFFFCC">
$in{'emailmessage'}</table></body>

That should be it, if not, see you tomorrow.

rog




Quote Reply
Re: emailthis mod....wanna push it further.. In reply to
Hello Paul,

Just a couple of alterations.

In your sub html_forward_email_htmlform

change <td><input type=hidden name="Image Name" value=""
to

<td><input type=hidden name="Image Name" value="html"

Replace 'Image Name' with your Image fieldname.

We also need to tell Sender about html for certain applications, the quickest way is to add another elsif.

After this routine in sub forward_email

if ($in{'Image Name'} eq "")
{ $sender = new Mail::Sender
{smtp => $smtp_server,
from => ($in{'email'})
};
$sender->MailMsg({to => ($in{'to_email'}),
subject => ($in{'subject'}),
msg => ($in{'emailmessage'}),})
or die "$Mail::Sender::Error\n";

}

add

elsif ($in{'Image Name'} eq "html")
{ $sender = new Mail::Sender
{smtp => $smtp_server,
from => ($in{'email'}),
ctype => 'text/html'
};
$sender->MailMsg({to => ($in{'to_email'}),
subject => ($in{'subject'}),
msg => ($in{'emailmessage'}),})
or die "$Mail::Sender::Error\n";


}

Replace 'Image Name' with your Image fieldname.

cheers

rog

Quote Reply
Re: emailthis mod....wanna push it further.. In reply to
Hello Paul,


I forgot to add error checking with the new HTML form if any of the fields were missing.

I have also made the HTML "page" hidden from the user which I think is far better, it looks a lot nicer, but you can use it as it was originaly or the new way, for the new way I have created a comments box for the sub html_forward_email_htmlform.

Full details can be found on the updated page.
http://www.fastcom.uk.com/...ecord_withimages.txt

Demo is at
http://www.fastcom.uk.com/.../db.cgi?db=bookstore

cheers

rog

Quote Reply
Re: [rog] emailthis mod....wanna push it further.. In reply to
I am trying to implement this MOD to use some records as a postcard system. I got the instructions from:

http://www.fastcom.uk.com/dbman/forward_record_withimages.txt

before they were removed. The record forwards, but without the image. In the description that gets sent, there is a line that reads:

Graphic: Yes

But no image is sent, even though I've checked the, "Send this record's Image" box.

Please help!
Quote Reply
Re: [jadey] emailthis mod....wanna push it further.. In reply to
The mod states:

# This mod will allow your users to mail the contents of a record to themselves or someone else,
# including images (if they choose to) and if they are defined in a field.

Are you storing the actual filename in a field as per the instructions?
If so, then in the following sub have you renamed to your field names as instructed?

In sub html_forward_email_form

#Change name= and value= to your fieldname and remove this comment line completely

<td><input type=checkbox name="Image Name" value="$rec{'Image Name'}" size=40><$font>$rec{'Image Name'}</font></td></tr>

I'm not sure this would work with the image upload mod which doesn't store the actual filename in the database.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] emailthis mod....wanna push it further.. In reply to
Hello, thanks for your reply. Yep, I have that information changed and set to:

<input type=checkbox name="Graphic" value="$rec{'Graphic'}" size=40><$font>$rec{'Graphic'}

Then in default.cfg:

Graphic => [9, 'alpha', 0, 3, 0, '', 'Yes']

Hrm, maybe it shouldn't be alpha?
Quote Reply
Re: [jadey] emailthis mod....wanna push it further.. In reply to
This seems to be part of the problem... You know in html.pl the line you just asked me for? Well it is supposed to print out the image after that according to the code:

<input type=checkbox name="Graphic" value="$rec{'Graphic'}" size=40><$font>$rec{'Graphic'}</font></td></tr>

but it doesn't. If I view source on the HTML, it shows this as:

<input type=checkbox name="Graphic" value="129/Yes" size=40>><font face="veranda,arial,helvetica" size="2">Yes</font></td></tr>

That's not good! Well "Yes" is what's in the actual database, instead of the image name. The email also says, "The image you selected could not be found"

I am also using the file upload mod to put the images there, so images are going in a subfolder that is named after the ad's unique ID field.
Quote Reply
Re: [jadey] emailthis mod....wanna push it further.. In reply to
I got it to work! Here's my html.pl code:

<input type=checkbox name="Graphic" value="/$rec{$db_key}/$rec{$Graphic}/$rec{'Userid'}.JPG" size=40><$font><img src="$SAVE_DIRECTORY_URL/$rec{$db_key}/$rec{$Graphic}/$rec{'Userid'}.JPG">

Last edited by:

jadey: Oct 11, 2002, 11:47 AM