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.

LVL 18
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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

easy to use so why reinvent the wheel


mgcITAuthor Commented:
ok, I downloaded the file ( 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


Please *don't* use FormMail from

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

You want FormMail from
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

mgcITAuthor Commented:
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.

Let's start from the begining then.

1.  You need to find out (if you don't already know), where you can run Perl/CGI scripts.  On most webservers, you have a cgi-bin directory to put the scripts in, however in some cases, you can put the script where ever you like so long as it has a recognised extension like .cgi or .pl  (for these purposes, I'll assume you have a cgi-bin).

2.  Copy into your cgi-bin directory.  As you are a windows server, you may need to rename it FormMail.cgi

3.  At this point, see it the webserver recognises it by entering into your browser.

4.  Assuming you don't get any errors, you can now configure the options you need.  The most important ones are $mailprog (set to your SMTP server name), and possibly @allow_mail_to and @recipients

5.  Then create your HTML form and point it to /cgi-bin/  See the README and Examples for more details.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mgcITAuthor Commented:
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:

  $DEBUGGING         = 1;
  $emulate_matts_code= 0;
  $secure            = 1;
  $allow_empty_ref   = 1;
  $max_recipients    = 5;
  $mailprog          = '/usr/lib/sendmail -oi -t';
  $postmaster        = '';
  @referers          = qw( localhost);
  @allow_mail_to     = qw( localhost);   ****These are the only 2 lines I changed
  @recipients        = (;                        ****
  %recipient_alias   = ();
  $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';
Subject: form submission

Thank you for your form submission.

mgcITAuthor Commented:
ahh think I may have figured it out...

for @recipients I put:

 @recipients        = qw(;    

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.
mgcITAuthor Commented:
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.
mgcITAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.