24/7/365 Support(866) 96-GATOR
  1. Knowledge Base
  2. >
  3. Email
  4. >
  5. Custom Form Mail

Custom Form Mail

FormMail is a very popular tool to capture information in a simple form and send this to an email address. It is relatively easy to set up and does its job well. However, spammers have found security holes in previous versions, allowing exploitation of email accounts on the host server.

Note: FormMail is not available on Windows servers. Use the Windows section of the following article for Windows servers:

HostGator recommends using the standard "server-wide" FormMail script described below whenever possible.

The following tutorial provides the code for a default FormMail script. Please select the link below to toggle the text.

  1. Copy the below code.
  2. Replace the words in bold black with your domain name and your email.
  3. Replace the words in bold blue with whatever you want that part of the form to say.
  4. Save it as an .html file.
  5. Upload and you are done.
Version 1 (No Validation)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>FormMail Demo</title>
</head>
<body>
<form action="http://www.mydomain.com/cgi-sys/formmail.pl" method="post">
<input type="hidden" name="recipient" value="youremail@here.com">
<input type="hidden" name="subject" value="FormMail E-Mail">
Whatever you want to say here<br><br>
<input type="text" name="email" size="20" value="Visitor E-Mail"><br>
<input type="text" name="tellme" size="20" value="E-Mail Content"><br><br>
<input type="submit" name="submit" value="E-Mail Me!">
<input type="hidden" name="redirect" value="http://mydomain.com/redirect-path">
</form>
</body>
</html>
Version 2 (Javascript Validation)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>FormMail Demo</title>
<script type="text/javascript">
function hgsubmit()
{
if (/\S+/.test(document.hgmailer.name.value) == false) alert ("Please provide your name.");
else if (/^\S+@[a-z0-9_.-]+\.[a-z]{2,6}$/i.test(document.hgmailer.email.value) == false) alert ("A valid email address is required.");
 else if (/\S+/.test(document.hgmailer.comment.value) == false) alert ("Your email content is needed.");
  else {
       document.hgmailer.submit();
       alert (' Thank you! \n Your email is sent.');
       }
}
</script>
</head>
<body>
<form action="http://www.mydomain.com/cgi-sys/formmail.pl" method="post" name="hgmailer">
<input type="hidden" name="recipient" value="myemail@mydomain.com">
<input type="hidden" name="subject" value="FormMail E-Mail">
Whatever you want to say here<br><br>
Visitor Name: <input type="text" name="name" size="30" value=""><br>
Visitor E-Mail: <input type="text" name="email" size="30" value=""><br>
E-Mail Content: <textarea name="comment" cols="50" rows="5"></textarea><br><br>
<input type="button" value="E-Mail Me!" onclick="hgsubmit();">
<input type="hidden" name="redirect" value="http://www.mydomain.com/redirect-path">
</form>
</body>
</html>
Note: This is a basic script and we cannot guarantee its usage nor offer direct support in modifying the code or troubleshooting. If you require assistance, please contact a developer for additional support, or HostGator Design Services for a customized solution.

Server-Wide FormMail

This was deprecated by cPanel in v60 and removed in v64 for VPS and Dedicated Server packages.

HostGator suggests that you use the above FormMail script whenever possible. This "server-wide" script ensures that you will not be held accountable if there are any exploits found on this version of FormMail.

Server-wide FormMail Considerations

There are a few points to keep in mind when using the server-wide FormMail script:

  • Make sure you use an email address on your HostGator server. For security reasons you may not use an outside email address. However, you can always use a mail fetching service to send the information on to an outside email address.
  • The server-wide FormMail option does not work with reCAPTCHA, as you cannot edit the server-wide script.
reCAPTCHA is a Google service which lets you embed a CAPTCHA in your web pages in order to protect them against spam. This article from Google has more information:

Custom FormMail Scripts

If you have a customized FormMail script you wish to use, including those created with third-party form generators, please make sure that it complies with our Terms of Service and Acceptable Use Policy.

Note: HostGator cannot support third-party scripts. For assistance with unique scripting requirements, site customization or website design, please contact our HostGator Design Services for a quote.