This guide shows you how to set up FormMail, the NMS Perl script that converts a contact form submission into an email message. FormMail runs as a Common Gateway Interface (CGI) script on a VPS or Dedicated Server. If you host on Shared hosting, read the warning first.
Warning: FormMail is not supported on InMotion Hosting Shared hosting plans, and mail sent through it is blocked on Shared servers. The script sends mail without authenticating with a mailbox, and Shared servers block unauthenticated script-generated mail. If you host on Shared, use SMTP authentication instead, which is the recommended method for sending mail from your site: Using PHPMailer to Send Mail through PHP.
Notice: Before you begin, download the FormMail “compat” package from NMS FormMail. The compat package is the easiest one to install.
Set Up FormMail
Customize the FormMail.pl script
- Un-compress the file you downloaded, then upload
FormMail.plto thecgi-bindirectory. You only needFormMail.pl; the rest of the download is documentation. - Open
FormMail.pland find the@referersline. Replace the example entries with your own domain, both with and withoutwww, separated by a single space:
@referers = qw(example.com www.example.com);- Find the
@allow_mail_toline. List the email addresses that the form is allowed to send to, separated by a single space, and removelocalhostfrom the list:
@allow_mail_to = qw([email protected] [email protected]);- Save
FormMail.pl.
Configure your contact form
- Point your contact form’s
actionattribute at the script:
<form ac Code tion="https://www.example.com/cgi-bin/FormMail.pl" method="post">Note: Replace example.com with your own domain, and update the path if you uploaded FormMail.pl to a location other than cgi-bin.
- Add hidden fields to your form so FormMail knows where to send the submission. Start with the
recipientfield, which sets the email address the submission is sent to:
<input type="hidden" name="recipient" value="[email protected],[email protected]" />Warning: Every address you list in recipient must also appear in the @allow_mail_to line in FormMail.pl. If it does not, FormMail returns a bad recipient error page instead of sending the message.
- Add a
subjectfield to set the subject line of the email:
<input type="hidden" name="subject" value="From the contact form" />- Optionally, add a
redirectfield to send the visitor to a thank-you page after a successful submission:
<input type="hidden" name="redirect" value="https://www.example.com/thankyou.html" />Note: Replace the URL with your own thank-you page. If you leave this field out, FormMail displays its own confirmation page listing the submitted fields.
Change file permissions
Important: Set the permissions on FormMail.pl to 755. The file needs execute permission, or the web server cannot run the script and your contact form returns an error instead of sending mail.
Change permissions using cPanel
- Log in to cPanel.
- Under Files, click File Manager.
- Navigate to
public_html, thencgi-bin. - Right-click
FormMail.pland select Change Permissions. You can also select the file and click Permissions in the toolbar. - Set User to read, write, and execute (rwx), and set Group and World to read and execute (r-x).
- Click Change Permissions to save.
Change permissions using SFTP
If you manage your files with a Secure File Transfer Protocol (SFTP) client instead, connect to your server, browse to the cgi-bin directory, and right-click FormMail.pl. Choose the option for changing file permissions, which most clients label File Permissions or CHMOD, then set the value to 755.
Your FormMail script is now set up and ready to process submissions from your contact form. Submit a test entry to confirm mail arrives at the address you configured. If delivery does not go through, check that the recipient address also appears in the @allow_mail_to line.