Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Email form

by perlTech
on Mar 07, 2005 at 17:01 UTC ( #437258=perlquestion: print w/replies, xml ) Need Help??
perlTech has asked for the wisdom of the Perl Monks concerning the following question:

Hi ever one Iam new to perl, have to write email form in perl, would any one please guide me how to do that, which one is best prectice, either design html page and add perl coding or generate html dynamicaly in perl, and one could pleas guide me any tutorial related to specific peroblem. thanks sam

Replies are listed 'Best First'.
Re: Email form
by gellyfish (Monsignor) on Mar 07, 2005 at 17:08 UTC

    Whilst I wouldn't want to discourage you from learning Perl , when it comes to form to email programs I would gently guide you toward NMS to find something that has already been done. This wheel has been invented many times before and a lot of mistakes have been made and remedied.


Re: Email form
by mpeters (Chaplain) on Mar 07, 2005 at 17:35 UTC
    This is not a prebuilt script but rather a module that you can use to easily build a mailpage: CGI::Application::MailPage.

    Update: - This module helps to build a 'email this page to a friend' form. If you are just looking for a standard 'email this info to an address' then look at CGI::Application::MailForm which comes with CGI::Application.
Re: Email form
by jonadab (Parson) on Mar 07, 2005 at 22:02 UTC

    I always use Mail::Sendmail for the purpose of sending mail. Easy to use, works great.

    As far as generating the HTML, for this you can probably just embed entire web pages into heredocs, so that your web pages are *almost* static, but then you can just interpolate any particulars you need. That technique will not be adequate for more complicated purposes, when the page needs to be more fully dynamic, but here you've basically only got two or three pages: a form for the user to fill in, a "sent" message, and possibly a "failed" message. They don't need to change much, other than (say) interpolating an error message.

    Update: Be sure to hardcode the To: address, so that spammers can't abuse your script to send to arbitrary recipients.

Re: Email form
by RazorbladeBidet (Friar) on Mar 07, 2005 at 17:07 UTC
    A quick Google searched turned up this - I'm sure you can find much more out there.

    Update: link removed because the example it links to is apparently morally repugnant

    Updated Update: link reinserted to provide context.

    Updated Update Part II: As stated below, the above was mentioned to provide the OP a means with which to answer his or her own question. The code linked to was given a cursory glance but was never intended to be a "production-ready example" to throw onto a Fortune 100's website, merely an example of the kinds of things that can be found in the span of a few moments spent searching. It was a bit careless on my part to so quickly link to something such as that, but again, it wasn't intended to be a foaming cup of yak urine, as Corion so eloquently stated.
    It's sad that a family can be torn apart by such a such a simple thing as a pack of wild dogs

      Please do not recommend random Perl scripts on the web without having verified them. The script that you recommended contains ugly errors that make it easy to send spam via the script:

      ... $Email = $in{'Email'}; $Message = $in{'Message'}; ... sub SendAutoReply { open (MAIL,"|$MailProgram -t"); print MAIL "To: $Email\n"; print MAIL "From: $YourEmail\n"; print MAIL "Subject: $Subject\n"; print MAIL "$Header\n"; print MAIL "$Date\n\n"; print MAIL "$Subject\n\n"; print MAIL "You sent the following:\n\n"; print MAIL "==============================\n\n"; print MAIL "Name: $Name\n"; print MAIL "Email: $Email\n\n"; print MAIL "Message:\n\n"; print MAIL "$Message\n\n"; print MAIL "==============================\n\n"; print MAIL "$TailMessage\n\n"; print MAIL "Best regards,\n\n\n"; print MAIL "$Signature1\n"; print MAIL "$Signature2\n\n"; close (MAIL); }

      If $Email contains a newline, you can spam any address through this form (and it is nowhere verified that $Email doesn't contain a newline and more data). Of course, there will be some fluff data trailing the spammers message, but if the spammer cared, he would have a different profession.

      Update: Finished incomplete sentence about verification of $Email

        The intent was to show the OP how easy it was to find information on the subject through Google. I neither recommended nor endorsed the script.

        Update: Ending digressive conversation here.
        It's sad that a family can be torn apart by such a such a simple thing as a pack of wild dogs

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://437258]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2018-04-20 09:46 GMT
Find Nodes?
    Voting Booth?