OzNewbie has asked for the wisdom of the Perl Monks concerning the following question:

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:

############################### # 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, &tempw +iz_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; }

Replies are listed 'Best First'.
Re: trying to create a resend password function
by ikegami (Patriarch) on Nov 15, 2009 at 05:15 UTC
    I presume you're asking for direction (as opposed to asking us to do the work for you). If so, I'd use Template and MIME::Lite.
Re: trying to create a resend password function
by merlyn (Sage) on Nov 15, 2009 at 04:32 UTC
    I'm betting you didn't write this code. I suggest you either (a) contact the person who wrote this code to help you (and if they need help they can come here), or (b) you learn some Perl, and then ask an actual Perl question.

    -- Randal L. Schwartz, Perl hacker

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: trying to create a resend password function
by Your Mother (Archbishop) on Nov 18, 2009 at 19:50 UTC

    And it's worth mentioning that a password reminder mailer is typically only possible if you store passwords in plain text. This is weak security and shouldn't be done. Passwords should be encrypted or at least hashed. You're stuck with legacy software in this case so this more FYI than anything else.

Re: trying to create a resend password function
by Sinistral (Monsignor) on Nov 18, 2009 at 18:42 UTC

    The answer by ikegami is a good starting point, as those modules will get you both MIME e-mail creation and a templating solution.

    The most direct answer to your question is that you or someone will have to modify the contents of the sendemail function that your snippet shows being invoked. Since senemail is not part of the Perl core language or of the standard module set shipped with Perl, it must have been written at the same time as your application. That's the modify point you need, where you will be adding code to use Text::Template, HTML::Template, or Template::Toolkit to have templates that will be turned into MIME attachments by MIME::Lite

Re: trying to create a resend password function
by Anonymous Monk on Nov 15, 2009 at 14:15 UTC
    Guys, this is totally uncalled for, why do you think OzNewBie would come around here, I mean, instead of us being on the offensive, show him what things he got to learn in File Handling, how to redirect the I/O...There's no need for you nor him to be barking at each other...
      The OP does not say, but does imply, that s/he had written the original code being modified.

      If that were the case, the OP would have the background to make the desired changes and wouldn't have needed to ask.

      Had the OP simply stated "this is legacy code, and I don't want to pay to have it modified", the responses might have been different. Might. (Though to be honest, I'd still second the 'Hire a programmer!' sentiment...)