CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Umm... little help please! - E-mail function

 



OzNewbie
New User

Nov 14, 2009, 9:00 PM

Post #1 of 7 (1231 views)
Umm... little help please! - E-mail function Can't Post

Hi there,

I am trying to create a 'resend password' function as my members get a little confused sometimes (just as I am now!)...ah the irony!

In any case, the below code gets me to my output html template, however; I also want it to send details to the member via e-mail.

The below code gives me an e-mail and information in the subject line... but I don't know how to get information from let's say a .txt template with the message I want to say. any advice?

Here's the part that actually work's: go to www.yourstocktips.com.au/forgotpass.htm and type in "Nala" as the user name (dummy account).

Thanks!

OzNewbie

Here's the code:

Code
###############################  
# Send password
###############################
sub pm_send_password
{
open (DATABASE, "<${root}$database") or print $!;
if($flocking) {flock DATABASE, 2;}

while(($thisrow = <DATABASE>))
{
if ($thisrow =~ m/^$input{'login'}\|(.*)/)
{
&init($thisrow);
&sendemail($values{'email'}, $from, $subject_lost_password, &tempwiz_to_from);
$sent = 1;
}
}
if($flocking) {flock DATABASE, 8;}
close DATABASE;
if(!$sent){&init_errors; &err($error_message{'login not found'});exit;}
$input{'action'} = "lost_password_sent";
&tempwiz;
exit;
}



(This post was edited by OzNewbie on Nov 15, 2009, 4:22 PM)


FishMonger
Veteran / Moderator

Nov 15, 2009, 6:25 AM

Post #2 of 7 (1218 views)
Re: [OzNewbie] Umm... little help please! - E-mail function [In reply to] Can't Post

What does your template file look like?

Is this template to be used for the email or for the web page?

Side Notes:
Please use the code tags when posting blocks of code.

Don't use & when calling your subs unless it's required, such as when creating a reference to the sub.

No need to get an exclusive lock on a read filehandle, but you would what it on a write filehandle.

Use a lexical var for the filehandle instead of the bareword and use the 3 arg form of open.

Don't put multiple statements on a single line.


FishMonger
Veteran / Moderator

Nov 15, 2009, 6:35 AM

Post #3 of 7 (1213 views)
Re: [OzNewbie] Umm... little help please! - E-mail function [In reply to] Can't Post

I assume that the &tempwiz_to_from sub is what reads in the template file.

Please post that sub as well as the &sendemail sub.


Code
open (DATABASE, "<${root}$database") or print $!;

If that open call fails, why would you still proceed with the rest of the sub which depends on that call to succeed?


OzNewbie
New User

Nov 15, 2009, 5:48 PM

Post #4 of 7 (1189 views)
Re: [FishMonger] Umm... little help please! - E-mail function [In reply to] Can't Post

Hi FishMonger,

thank you for the note.

I think I should have put my enquiry in Beginner, as I overlooked something very simple. I have now fixed the problem.

I had set up the .txt template, named it correctly, but had not defined it in my .cfg file! D'oh! Crazy

Thank you,

OzNewbie


FishMonger
Veteran / Moderator

Nov 15, 2009, 7:39 PM

Post #5 of 7 (1185 views)
Re: [OzNewbie] Umm... little help please! - E-mail function [In reply to] Can't Post


In Reply To
Hi FishMonger,

thank you for the note.

I think I should have put my enquiry in Beginner, as I overlooked something very simple. I have now fixed the problem.

I had set up the .txt template, named it correctly, but had not defined it in my .cfg file! D'oh! Crazy

Thank you,

OzNewbie


There are more problems with your code than not defining the template filename. If you're satisfied with it as it is then ok, but if you want to improve it then I'll be here to help.


OzNewbie
New User

Nov 15, 2009, 10:49 PM

Post #6 of 7 (1173 views)
Re: [FishMonger] Umm... little help please! - E-mail function [In reply to] Can't Post

Hi FishMonger,

I now see what you were referring too. I really only need to use LOCK_SH instead of LOCK_EX.

You're right I should add a 'die' command to prevent the request going any further.

Something like:

Code
  open (DATABASE, "<${root}$database") || die("Cannot Open File");


Is that okay?



Thank you for your feedback.

It all helps my learning journey.

OzNewbie


FishMonger
Veteran / Moderator

Nov 16, 2009, 8:46 AM

Post #7 of 7 (1157 views)
Re: [OzNewbie] Umm... little help please! - E-mail function [In reply to] Can't Post


In Reply To
You're right I should add a 'die' command to prevent the request going any further.

Something like:

Code
  open (DATABASE, "<${root}$database") || die("Cannot Open File");


Is that okay?


That's "ok", but this is the preferred/better syntax.


Code
my $dbfile = $root . $database; 
open my $DATABASE, '<', $dbfile or die "Cannot Open <$dbfile> $!";


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives