Gossamer Forum
Home : Products : DBMan : Installation :

Problem with Private mailing mod...

Quote Reply
Problem with Private mailing mod...
Help,
I can't load the '%rec = &get_record($in{$db_key})' as a default or registered user. Only with my own records, when I will sent an email, the values are loaded.
What can be wrong??? I will post all my codes. Sorry for the scrolling...
Code:
sub html_send_email_form {
#--------------------------------------

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

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

if ($in{'Userid'}) {
$in{'Userid'} = $db_userid;
my ($status,@hits) = &query("view");

$in{'email'} = $hits[17];
$in{'name'} = $hits[22];
$in{'place'} = $hits[23];
$in{'phone'} = $hits[24];

$in{'emailmessage'} =
"Geachte $rec{'Naam'},
Kunt u met mij contact opnemen i.v.m. uw auto,
de $rec{'Merk'} $rec{'Type'}.
Alvast bedankt voor de moeite en tot ziens!!

Hoogachtend, $in{'name'}
$in{'phone'}
$in{'place'}
==============";
}

# <-- top of page formatting -->
print qq|
<html><head><title>$html_title: Email versturen</title></head>
<body bgcolor="#FFFFFF">
<center>
<table border=1 bgcolor="#D2FFD2" cellpadding=5 cellspacing=3 width=485 align=center valign=top>
<tr><td colspan=2 border=0 bgcolor="#006200">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Email versturen</b></td></tr>
<tr><td><p><center><$font_title><b>Email sturen</b></font></center><br>|;

# <-- introductory text -->
if ($message) { print qq|Los de fouten op:<br><font color="red"><$message|; }
print qq|<center>
<$font>Vul hier het Onderwerp in en de boodschap die verzonden moet worden aan <b>$rec{'Naam'}</b>.</font>
|;
# <-- email form -->

$in{'subject'} = "Re:$rec{'Merk'} $rec{'Type'}.";

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>Uw emailadres:</font></td>
<td><input type=text name="email" value="$in{'email'}" size=40></td></tr>
<tr><td align=right><$font>Onderwerp:</font></td>
<td><input type=text name="subject" value="$in{'subject'}" size=40></td></tr>
<tr><td valign=top align=right><$font>Boodschap:</font></td>
<td><textarea name="emailmessage" ROWS="4" COLS="40" WRAP="VIRTUAL" MAXLENGTH="255">$in{'emailmessage'}</textarea></td></tr>
</table><br>
<center>
<INPUT TYPE="SUBMIT" NAME="send_email" VALUE="Zend Email">
<INPUT TYPE="RESET" VALUE="Wis inhoud">
</table>
</form>
|;
# <-- end of page formatting -->
&html_footer;
print qq|</td></tr></table></body></html>|;
}

sub html_send_email_success {
#----------------------------------
my ($message) = $_[0];
&html_print_headers;
# <-- top of page formatting -->
print qq|
<html><head><title>$html_title: Email sturen</title></head>
<body bgcolor="#FFFFFF">
<center>
<table border=1 bgcolor="#D2FFD2" cellpadding=5 cellspacing=3 width=485 align=center valign=top>
<tr><td colspan=2 border=0 bgcolor="#006200">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Email sturen</b></td></tr>
<tr><td><p><center><$font_title><b>Email verzonden</b></font></center><br>
|;
# <-- text -->
print qq|<$font>De Email boodschap is verzonden aan $message.</font></table>|;
# <-- end of page formatting -->
&html_footer;
print qq|</td></tr></table></body></html>|;
}
And from the script:
Code:
sub send_email {
#-----------------------------------

unless ($in{'email'}) { $message = "You must fill in your email address<BR>"; }
unless ($in{'email'} =~ /.+\@.+\..+/) { $message = "Your email address is not in the correct format.<BR>"; }
unless ($in{'subject'}) { $message .= "You must fill in a subject for your message.<BR>"; }
unless ($in{'emailmessage'}) { $message .= "Your email message is empty.<BR>"; }
%rec = &get_record($in{$db_key});
if (!%rec) { $message .= "The email address you requested could not be found.<BR>"; }
if (!$rec{'Email'}) { $message .= "There is no email address on file for this person.<BR>" }
if ($message) {
chomp($message);
&html_send_email_form($message);
return;
}
open (MAIL, "$mailprog") | | &cgierr("unable to open mail program");
print MAIL "To: $rec{'Email'}\n";
print MAIL "From: $in{'email'}\n";
print MAIL "Subject: $in{'subject'}\n\n";
print MAIL "-" x 75 . "\n\n";
print MAIL $in{'emailmessage'};
close (MAIL);
&html_send_email_success($rec{'Naam'});
}
just posting my sub 'get_record' from the script:
Code:
sub get_record {
# --------------------------------------------------------
# Given an ID as input, get_record returns a hash of the
# requested record or undefined if not found.

my ($key, $found, $line, @data, $field, $restricted);
$key = $_[0];
$found = 0;
($restricted = 1) if ($auth_modify_own and !$per_admin);

if ($id_vk){$db_file_name = "/opt/guide/www.autorandstad.nl/cgi-bin/dbman/voorkeur.db";}

open (DB, "<$db_file_name") or &cgierr("error in get_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_; chomp ($line);
@data = &split_decode($line);
next LINE if ($restricted and ($db_userid ne $data[$auth_user_field]));
if ($data[$db_key_pos] eq $key) {
$found = 1;
for ($i = 0; $i <= $#db_cols; $i++) { # Map the array columns to a hash.
$rec{$db_cols[$i]} = $data[$i];
}
last LINE;
}
}
close DB;
$found ?
(return %rec) :
(return undef);
}
Hope that someone see whats wrong.

Thanks in advance.
---------
Mart.

[This message has been edited by mart (edited August 14, 1999).]
Quote Reply
Re: Problem with Private mailing mod... In reply to
You should never try to add more modifications to a mod until the mod works in the first place.

What is the link that you are using to get to sub html_send_email_form? Do you have the link in html_record, so that it's connected to a record?

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





Quote Reply
Re: Problem with Private mailing mod... In reply to
Yes, its in the html_record_long, its just the way I've copied it, <a href="$db_script_link_url&$db_key=$rec{$db_key}&send_email_form=1">Send email to this person</a>
so...
Quote Reply
Re: Problem with Private mailing mod... In reply to
I think your problem is the line

if ($in{'Userid'}) {

There is probably nothing in the variable $in{'Userid'}.

Also, it would be better if you didn't use $in variables for
$in{'email'} = $hits[17];
$in{'name'} = $hits[22];
$in{'place'} = $hits[23];
$in{'phone'} = $hits[24];
$in{'emailmessage'} = ...

Just use
$email
$name
$place
$phone
$emailmessage

I don't understand when you say
Quote:
I can't load the '%rec=&get_record($in{$db_key})' as a default or registered user

The '%rec=&get_record($in{$db_key})' is getting the email for the recipient of the email -- this is whom you are sending the message to.

Did you try the mod as it was written before you started to modify it?

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





Quote Reply
Re: Problem with Private mailing mod... In reply to
Yes, I did try the unmodified mod, with the same result. The problem is that the %rec is not filled, also not with the emailadress of the owner of the record. When I use 'Email sent to $rec{'Name'}, the name won't appear. Its also strange to me, that it rather will work, when the userid is the same, as the owner of the record...

[This message has been edited by mart (edited August 14, 1999).]
Quote Reply
Re: Problem with Private mailing mod... In reply to
Okay, then, after

<body bgcolor="#FFFFFF">

add

$in{$db_key}

and see what you get. It should be the very first thing on your page.

Be sure to choose a record where you know what the key value should be so that you'll recognize it.

If that comes out okay, take out the line you added above and replace it with

Code:
|;
foreach $key (sort keys %rec) {
print "$key: $rec{$key}<BR>";
}
print qq|

You should get the whole listing of the record.

Let me know what happens.

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





Quote Reply
Re: Problem with Private mailing mod... In reply to
Go back and take out everything you've added. Start with the backups you should have made before you added this mod. (You really should only add one thing at a time, so you can do this without losing other work.)

If you don't have a backup from before you added the private mailer, delete all of the private mailer subroutines. You can add them back in after the Javascript thing is finished.


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





Quote Reply
Re: Problem with Private mailing mod... In reply to
Hi,
With '$in{$db_key}', I'll get the number of the record, and with this code'|;
foreach $key (sort keys %rec) {
print "$key: $rec{$key}<BR>";
}
print qq|'
I only get a ':'. It still confuse me, why it will give the right values with a record, that belongs to the loggedin user.

Quote Reply
Re: Problem with Private mailing mod... In reply to
OK, I figure it out, but I have no explanation for this. When I delete the following code out of my 'html_record_long', it works.
This code you gave me a while ago, for holding and updating the 'hits' per record. (very good mod)
Code:
open (DB, "<$db_file_name") or &cgierr("error in modify_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>; # Slurp the database into @lines..
close DB;
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $rec{$db_key}) {
++$rec{'Teller'};
$output .= &join_encode(%rec);
}
else {
$output .= $line . "\n";
}
}
Maybe this explains, why the %rec only is loaded when a user owns the record. What would I do???

Thanks in advance.
-------
Mart.
Quote Reply
Re: Problem with Private mailing mod... In reply to
I make a completely mess of it. The reply I gave just a while ago you can forget. Now it still don't work without the code above. It only works with a logged in user, who calls his own record and sent an email to this 'person'. But for making it total confusing, when someone tried to send an email out of its 'preference list', the whole thing works correctly.
I hope you will take a look at my files, I've posted them in advance on http://www.autorandstad.nl/html_pl.txt and http://www.autorandstad.nl/db_cgi.txt .I'll thank you in advance for the help.

Mart.

[This message has been edited by mart (edited August 15, 1999).]
Quote Reply
Re: Problem with Private mailing mod... In reply to
I think we have to look for the fault somewhere in the script or maybe in html.pl, sub 'view_succes'.. Because when I change the names of the sub's 'html_record-long' and 'html_record_pref' it will not work in the 'pref' sub and it works good in the 'long' sub. So I switched it back. I have not the slightest idea where to look...
Quote Reply
Re: Problem with Private mailing mod... In reply to
OK, I start just before the (fine looking) preference list thing. I puzzle and see, if I get the solution. I'll let you know.

Thank you.
Greetings,
---------
Mart.
Quote Reply
Re: Problem with Private mailing mod... In reply to
Well, solve it, the fault was in the .cfg, $auth_modify_own = 1;
it must be $auth_modify_own = 0;
Quote Reply
Re: Problem with Private mailing mod... In reply to
No, Mart, that was my fault. I forgot about the line in sub get_record. Thanks for letting me know about it, though.

If you want to maintain the $auth_modify_own setting, delete

($restricted = 1) if ($auth_modify_own and !$per_admin);

from sub get_record.

Thanks again for letting me know.


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





Quote Reply
Re: Problem with Private mailing mod... In reply to
One more thing,
I will define the 'senders' name, emailadres and phonenumber with this mail. I've tried the following code:
Code:
sub html_send_email_form {
#--------------------------------------

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

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

if ($db_userid ne "default") {
undef %in;
$in{'Userid'} = $db_userid;
my ($status,@hits) = &query("view");

if ($status eq "ok") {
$in{'email'} = $hits[17];
$in{'name'} = $hits[22];
$in{'phone'} = $hits[23];
$in{'place'} = $hits[24];
}

$emailmessage =
"Geachte $rec{'Naam'},

Kunt u met mij contact opnemen in verband met
uw auto-advertentie op de Site van Autorandstad,
de $rec{'Merk'} $rec{'Type'} van $rec{'Bouwjaar'}.

Alvast bedankt voor de moeite en tot ziens!!

Hoogachtend,
$in{'name'}
$in{'phone'}
$in{'place'}
==============";
}


# <-- top of page formatting -->
print qq|rest of code...
but the line 'undef %in' deletes the value of '$in{$db_key}', so is there another solution for this???
Quote Reply
Re: Problem with Private mailing mod... In reply to
Carol,

I was also experiencing the problem with getting the record for the default user. I took your suggestion and remmed out (#) the following line:

Code:
($restricted = 1) if ($auth_modify_own and !$per_admin);

Works fine for me now. Smile

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

[This message has been edited by Eliot (edited August 16, 1999).]
Quote Reply
Re: Problem with Private mailing mod... In reply to
Mart--

If the userid is the key value in your database, instead of

Code:
if ($db_userid ne "default") {
undef %in;
$in{'Userid'} = $db_userid;
my ($status,@hits) = &query("view");
if ($status eq "ok") {
$in{'email'} = $hits[17];
$in{'name'} = $hits[22];
$in{'phone'} = $hits[23];
$in{'place'} = $hits[24];
}

you can use

Code:
%rec2 = &get_record($db_userid);

And then, instead of defining all those variables, you would just use

$rec2{'Fieldname'}

If your userid field isn't the key, it won't matter that the $in{$db_key} is erased. You already have used it to get the values into the %rec hash for the recipient of the email. You don't need that value any more.

Also, it's really not a good idea to use variables like:

Code:
$in{'email'} = $hits[17];
$in{'name'} = $hits[22];
$in{'phone'} = $hits[23];
$in{'place'} = $hits[24];

for this. It is much better if you use

Code:
$email = $hits[17];
$name = $hits[22];
$phone = $hits[23];
$place = $hits[24];

and change the variables in your outgoing email to match.

Eliot--

I had forgotten that line was there in sub get_record. The original script only uses get_record for the modify form. Taking it out shouldn't be any problem, though.


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





Quote Reply
Re: Problem with Private mailing mod... In reply to
Wow...cannot come out.
When I use 'undef %in', it wil also lose the value of the emailadress, who will gets the message, so the error message came:'There is no email address on file for this person', I've tried almost everything, but there must be some easy solution for loading some values out of a user his record and use them in this message. I'm now using this code, but without the 'undef %in' rule, it will not load the values out of the user's record.
if ($db_userid ne "default") {
here should be the 'undef %in;' rule
$in{'Userid'} = $db_userid;
my ($status,@hits) = &query("view");
if ($status eq "ok") {
%rec2 = &array_to_hash($_, @hits);
$mail = $rec2{'Email'};
$name = $rec2{'Naam'};
$phone = $rec2{'Telefoon'};
$place = $rec2{'Woonplaats'};
}
}
Would you give it a try???

[This message has been edited by mart (edited August 17, 1999).]
Quote Reply
Re: Problem with Private mailing mod... In reply to
In your form, use

<input type=hidden name="$db_key" value="$rec{$db_key}">



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





Quote Reply
Re: Problem with Private mailing mod... In reply to
OK, were out.
I've tried maybe a thousand times something with '<input type=hidden name="$db_key" value="$in{$db_key}">' but now its working.

Thank you...

Greetings,
--------
Mart.