Link to home
Start Free TrialLog in
Avatar of mgcIT
mgcITFlag for United States of America

asked on

Sending email

First of all, I have never used CGI before so please bare with me...

I want to create an online form that users can fill out and have the info emailed back to me.  My hosting company tells me that I can use CGI and Perl on my site.  Please tell me what I need to accomplish this.  I have done this before using ASP but never CGI or Perl so I'm not sure how different it is.  Also please let me know if there is any specific information I need to get from my ISP.

Thanks.
Avatar of lengreen
lengreen

Hi

I wouldn't write your own, I would use Formmail available at

http://www.scriptarchive.com/

easy to use so why reinvent the wheel

cheers

Len
Avatar of mgcIT

ASKER

ok, I downloaded the file (FormMail.pl)... but I still don't really know how to use it.  What do I need to do to customize for my needs?  What I need to do is:

1. Format the email message that is going to be generated
2. Specify the email address to send it to
3. Where to put this file on my site (I have a /CGI-bin directory already set up so I'm guessing in that folder???)
4. Get the data from the form elements on my survey page to the Perl script

Thanks
Avatar of Tintin
Nooooo!!!

Please *don't* use FormMail from http://www.scriptarchive.com/

It is very poorly written and has had so many security flaws.

You want FormMail from http://nms-cgi.sourceforge.net/
Avatar of mgcIT

ASKER

ok Tintin, since you are the highest rated expert in this section I'll take your word for it.... but please walk me through this.  What (if anything) do I need to change in this new Perl file, and how do I get it up & running?  Again, I am a total novice with CGI and Perl so I'm looking for a REALLY easy example to follow.  I gave 500 points for this so I wouldn't have to do a lot of reading and research.

Thanks...
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mgcIT

ASKER

ok, when I upload that file, it appears to be working but when I change the @recipients to have my email address, I get an error.  Here is that section of the file:

BEGIN
{
  $DEBUGGING         = 1;
  $emulate_matts_code= 0;
  $secure            = 1;
  $allow_empty_ref   = 1;
  $max_recipients    = 5;
  $mailprog          = '/usr/lib/sendmail -oi -t';
  $postmaster        = '';
  @referers          = qw(dave.org.uk 209.207.222.64 localhost);
  @allow_mail_to     = qw(myemail@myaddress.com localhost);   ****These are the only 2 lines I changed
  @recipients        = (myemail@myaddress.com);                        ****
  %recipient_alias   = ();
  @valid_ENV         = qw(REMOTE_HOST REMOTE_ADDR REMOTE_USER HTTP_USER_AGENT);
  $locale            = '';
  $charset           = 'iso-8859-1';
  $date_fmt          = '%A, %B %d, %Y at %H:%M:%S';
  $style             = '/css/nms.css';
  $no_content        = 0;
  $double_spacing    = 1;
  $wrap_text         = 0;
  $wrap_style        = 1;
  $address_style     = 0;
  $send_confirmation_mail = 0;
  $confirmation_text = <<'END_OF_CONFIRMATION';
From: you@your.com
Subject: form submission

Thank you for your form submission.

END_OF_CONFIRMATION
Avatar of mgcIT

ASKER

ahh think I may have figured it out...

for @recipients I put:

 @recipients        = qw(myemail@myaddress.com);    

I didn't have the qw before so that was probably it.  I'll play around with this for a little while longer and let you know if I have any more trouble before finalizing this Q...

Thanks for all the help.
Avatar of mgcIT

ASKER

ok I ran into a few more snags.  The email is working correctly now, but I am having trouble customizing the email message and the Form submission page.

For the email message I need the following things:

1. How to set From address
2. How to set Subject line
3. How to edit body of email message (The default is rather vague and I'd like to type my own info there for the heading)

Secondly, after you submit the form it redirects to another page (I think) and I'd like to change that page to something else.  Either change the content on that page or use my own page but I have no idea how.

Thanks again...

1.   Are you wanting a user to specify their email address or have a fixed from address?

2.   You set that in the form, eg:

   <input type="hidden" name="subject" value="From the feedback form" />

3.  The email body is not so flexible (without editing the Perl code).  The main choices you have is:

$double_spacing     - If this is set to 1 (as it is by default) then a blank
                      line is printed after each form value in the e-mail.
                      Change this value to 0 if you want the e-mail to be
                      more compact.

$wrap_text          - If this is set to 1 then the content of any long text
                      fields will be wrapped at around 72 columns in the
                      e-mail which is sent.  The way that this is done is
                      controlled by the variable $wrap_style

$wrap_style         - If $wrap_text is set to 1  then
                      the text will be wrapped in such a way that the left
                      margin of the text is lined up with the beginning of the
                      text after the description of the field - that is to
                      say it is indented by the length of the field name
                      plus 2.  If it is set to 2 then the subsequent lines
                      of the text will not be indented at all and will be
                      flush with the start of the lines.  The choice of style
                      is really a matter of taste although you might find
                      that style 1 does not work particularly well if your
                      e-mail client uses a proportional font where the spaces
                      of the indent might be smaller than the characters in
                      the field name.
Avatar of mgcIT

ASKER

I just wanted to have a fixed From address, but I figured out how to do that using a hidden form element.  Having a different redirect page was the same process as well... just use a hidden element called "redirect".

Thanks for all of the help. It's working perfectly now.