• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

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.
0
mgcIT
Asked:
mgcIT
  • 6
  • 3
1 Solution
 
lengreenCommented:
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
0
 
mgcITAuthor Commented:
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
0
 
TintinCommented:
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/
0
Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

 
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.

Thanks...
0
 
TintinCommented:
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 FormMail.pl 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 http://www.yoursite.com/cgi-bin/FormMail.pl 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/FormMail.pl.  See the README and Examples for more details.



0
 
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:

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

0
 
TintinCommented:
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.
0
 
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.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now