Form To Email  

Support Topics: Form To Email: How to: Setup FormMail (PERL form to Email)

What you would use this for: To provide a web based form from which your visitors can send you an email.

What You Need:
An FTP client (Transmit - external link)
A text editor (TextWrangler - external link)
An activated CGI-BIN folder in your "public_html" directory on your site. (if you don't already have one setup for your site, please request one)

1. Go to http://www.scriptarchive.com/ (external link) and download the FormMail package.

2. If the installation package doesn't expand automatically, double click the formmail.zip file. This should force the compressed formmail.zip to expand into a folder called formmail.

3. Open the formmail folder. Inside you'll see a file called FormMail.pl. Spammers and hackers often seek to exploit cgi's named FormMail.pl and FormMail.cgi. To combat that, we'll need to change the name of this file. In our example, we'll change the name to 'YourUsernameMail.pl' (if you want to use this convention, change YourUsername to actually represent what your username is). To rename the file, click on the file to highlight it and then press the 'return' key. The name then becomes editable. Once you've retyped the new name, hit the return key again to accept the name change.

4. Open the YourUsernameMail.pl file in TextWrangler. We'll need to change some variables here. The first line we'll need to examine at the very top, which defines the path to PERL on the server:

#!/usr/bin/perl

This line is already correct, so no changes need to be made. On all PERL scripts, you'll need to check this line and make sure the path to PERL is set as #!/usr/bin/perl.

5. The next variable we'll need to look at is further down the page, and probably the first item in a color other than black:

$mailprog = '/usr/lib/sendmail -i -t';

This variable defines the path to the Send Mail program on your server. This line should be changed to:

$mailprog = ' /usr/sbin/sendmail -i -t';

6. The next variable that needs to be changed is:

@referers = ('scriptarchive.com','209.196.21.3');

This variable is used to verify the domain that is sending the form and to verify the recipients email. So if the mail from the form is being sent from examplesite.com and to me@examplesite.com, then we'd use the following information:

@referers = ('examplesite.com');

Do not put www.examplesite.com to define this variable, as people may access your site with or without the www. Use the formatting as written above.

In the example above we left out the IP address and the preceding comma. The reason for this is that your IP address may change and including such a strict variable may break your form and cause hours of needless troubleshooting and frustration. Since this variable has only a minor effect on security, it shouldn't be an issue to leave out the IP address.

These instructions are intended only for sending mail from your site to an address at the same address (e.g., from examplesite.com to me@examplesite.com). If you intend to have mail sent from your site to an email address not at your domain, then we suggest that you have a look at the Read Me file that was included in the FormMail.zip package.

7. Save this file by pressing command + s

8. Login to your server space and upload the YourUsernameMail.pl file into the public_html > cgi-bin folder.

9. You'll need to make sure the .pl file you just uploaded has the correct permissions. To do this using Transmit, highlight the YourUsernameMail.pl and press command + i. In the window that pops up, you can either type 755 into the bottom field. Click Apply.

10. We now have to create the form. Below is HTML code for the form. This code is only for the form element of your page and is not a complete HTML document. It is meant for you to paste into an existing HTML document's code.

<FORM method="post"
ACTION="/cgi-bin/YourUsernameMail.pl">
<input type=hidden name="recipient" value="me@examplesite.com">
<input type=hidden name="redirect" value="http://www.examplesite.com/response.html">

Your Name: <input NAME="realname"><br>
Your Email Address: <input NAME="email"><br>
Subject: <input NAME="subject"><br>
Message: <input NAME="message"><p>
<input type="submit" name="Submit" value="Submit">

</FORM>

You will need to change a couple of things and you may want to change others. So, let's break down the following information line by line.

<FORM method="post"
ACTION="/cgi-bin/YourUsernameMail.pl">


This tells the form where to submit to. You'll want to change YourUsernameMail.pl to whatever you've chosen to name your FormMail.pl script.

<input type=hidden name="recipient" value="me@examplesite.com">

This is the only required field. It tells the mail script where to send mail submitted using this form.

<input type=hidden name="redirect" value="http://www.examplesite.com/response.html">


This field will be hidden on your form, but it tells the server which page to serve up upon successful submission of the form.

Your Name: <input NAME="realname">

This is the field where your guest will type in their name.

Your Email Address: <input NAME="email">

This is the field where your guest will type in their email address.

Subject: <input NAME="subject">

This is the field where your guest will type in a subject line for the email they are sending you. You can also specify the subject line of the email, instead of leaving it up to your guests. The way to do that would be to replace the Subject: <input NAME="subject"> line with <input type=hidden name="subject" value="My Subject Line"> Of course, you'd want to replace "My Subject Line" with your desired subject.

Message: <input NAME="message">

The is the field where your guest will type their message to you.

<input type="submit" name="Submit" value="Submit">


This line creates that nifty little submit button at the end of the form.

</FORM>

This closes out the form.

10. Create a page thanking your visitor for sending you mail and save it as response.html

11. Upload the page that contains your form and your response.html page into your public_html folder.

12. That's it. You should be able to point your browser to the page that contains your email form and send yourself an email.

Support Topics

Blogs
Calendars
E-Commerce
Email
Form to Email
Guestbooks
Hit Counters
MacHighway Banners
Mailing Lists
Message boards and Forums
PERL
PHP & MySQL
Security
Site Wide Search Engines
Spam
SSL
Traffic Reports
Uploading / Publishing
Video
WebDAV