HostGator.com » Support Portal

Steps to making a form on your website where people can email you information (formmail)

If you want help making on online form so visitors send you emails directly from your website, then please view this tutorial page.

If you want to update your existing email form, simply copy the first FORM tag, and paste it over your current FORM tag. You will also need to copy each INPUT tag which says type="hidden".

I apologize, but we do not support any site design or coding.

You can create your own custom online forms using a form generator, like phpFormGenerator (found in Fantastico).

Please see important information on how to use phpFormGenerator, as it requires special setup to get working.


What is a FORM tag? This is a form tag, starting with the less-than symbol and ending with the greater-than symbol, and it says "form, action equals something, method equals something".

<form action="http://www.mydomain.com/cgi-sys/formmail.pl" method="post">

Article Comments

Tony
I purchased a script for a more extensive contact form. It has the following PHP code that links to a flash file. Where would I put the form tag and is that all I need to do?

<?PHP
// on some servers you need to add this code in order to work without problems
$firstName = $_REQUEST["firstName"];
$lastName = $_REQUEST["lastName"];
$theCompany = $_REQUEST["theCompany"];
$thePhone = $_REQUEST["thePhone"];
$theEmail = $_REQUEST["theEmail"];
$theMessage = $_REQUEST["theMessage"];

$to = "myname@mydomain.com";
$subject = "Contact Form";
$message = "First Name: " . $firstName;
$message .= "\nLast Name: " . $lastName;
$message .= "\nCompany: " . $theCompany;
$message .= "\nPhone Number: " . $thePhone;
$message .= "\nEmail: " . $theEmail;
$message .= "\nIP Adress: " . $_SERVER['REMOTE_ADDR'];
$message .= "\nBrowser: " . $_SERVER['HTTP_USER_AGENT'];
$message .= "\n\nMessage: " . $theMessage;
$headers = "From: $theEmail";
$headers .= "\nReply-To: $theEmail";


$sentOk = mail($to,$subject,$message,$headers);

echo "sentOk=" . $sentOk;

?>

HostGator
You must save this PHP code as file on your site. Here I am using email.php as the example.

You must also create an email form like the one we provide; however, the form must accept text fields with the names your PHP script is expecting (i.e. firstName, lastName, theCompany, thePhone, theEmail, and theMessage).

Then, instead of using:
action="http://www.mydomain.com/cgi-sys/formmail.pl"

you must use:
action="http://www.mydomain.com/email.php"

gina
Yes i knwo it will send me an email with the form information in the email. What i am try to get across is: i set up a form with name, phone, address, email, etc..........when i receive the email name is at the end of the form, it is throwing it out of order!

HostGator
Gina, sounds like you are using your own custom code, so I will not be able to make it work the way you want.

Fortunately, I can offer you some advice.

Note the action value in your form. It refers to some file on your account. Find that file and open it for editing. This file writes your email, so make sure it is writing the input in the order you want.

EXAMPLE STEPS:
A PHP form will say <form action=".../something.php">

Find something.php in File Manager and click Edit.

The code might have a part which looks like this:

$message = "Here is a new email from your website!\n";
$message.= "Here is the visitor phone: $phone \n";
$message.= "Here is the visitor address: $address \n";
$message.= "Here is the visitor name: $name \n";
mail ($to, $subject, $message, $headers);

You just need to move the line for the visitor name above the lines for phone and address.

Nir
I made a form - when I set the email inside to php to send it to an email in the domain - the email is not sent.
When I set the email inside the php to send it to an external email - it does work.
Is there a limitation on sending emails to your own domain ?

HostGator
There is no limitation. Perhaps the email on the domain is blocking the message due to possible spam.

Make sure you can receive normal emails, and then try changing the PHP code so that the From header is your cPanel username@your server name.

EXAMPLE:
Change:
$success = mail($EmailTo, $Subject, $Body, "From: <$VisitorEmail>");
to:
$success = mail($EmailTo, $Subject, $Body, "From: <me123@gator123.hostgator.com>");

Of course, you must replace me123 with your cPanel username and gator123.hostgator.com with your server name. You may call us or join live chat to get those names.

Bon
What code do I use to have my contact form submit to my gmail

HostGator
Create an email forwarder to send emails from fakename@yourdomain.tld to your gmail or any other 3rd party email.

Then point the online form to your fakename@yourdomain.tld and the emails will be delivered where you want.

David Tierney
There is conflicting information above in this thread with regard to having the form results sent to an email address other than on the hostgator server. Originally this seemed to be required I believe on one of the earlier script versions. Above someone from Hostgator says, with regard to this: "There is no limitation"; but then later another Hostgator response references setting up a forward to have it sent outside. Can someone clarify? thanks.

HostGator
The "no limitation" comment was specifically for Nir's question regarding PHP mail forms. That has nothing to do with the email form HostGator provides.

The form we provide still requires you to use an email address on the same server. Using an email forwarder to deliver off server (e.g. Gmail or Hotmail) is still the best option.

Ela
In your tutorial I have to put my email address in the script, meaning that spammers can find it in the code and use it. Is there a way to hide the email address in the code?

HostGator
You can create a custom PHP form which keeps the email address unseen.

Please read the related article on "How to use sendmail with PHP".

Tony
Does this script make it possible to carry form field values from page to page before sending to the receipient? I'd like to create a multi-page form to take information on one page, confirm the same on the next page, then mail the final confirmed version to an address. Can do?

HostGator
This HostGator form does not have the custom features you request.

You may create your own PHP form, or you may install a program which helps you create custom PHP forms.

Eric
How do we make the "email content" box not only wider, but taller?

HostGator
Replace the line:
<input type="text" name="tellme" size="20" value="">

with:
<textarea name="tellme" cols="50" rows="5"></textarea>

I am planning some more updates to these forms in the near future.

Greg
How do I set the replyto field to be the value of an input field so that the address that is entered in the form becomes the "from" or reply to field?

HostGator
You cannot modify the email headers for the script included with cPanel.

You may create a PHP form which defines the reply-to field. I suggest the PHP Form Generator found in Fantastico DeLuxe.

AL
What value, if any, would be necessary to include a subject-input in the form as shown here: http://www.hostgator.com/formmail.shtml

HostGator
Just change the tag which is already included.

<input type="hidden" name="subject" value="FormMail E-Mail">

to

<input type="text" name="subject" value="FormMail E-Mail">

Marco
The javascript version of the form only has three fields. I want to create fields for Complete_Name, Company_Name, Email, and Message. I modified the form, but I am not sure if this will work. What are your suggestions?

HostGator
I am developing a new version 2, which includes an extra field for Name.

You can modify the form and test it. Some extra fields work, some do not.

Bryan
I am having my Web Designer make a website with Wordpress. I'll have many forms for people to send. After reading this article it worries me that I won't be able to have custom forms. Is he going to have to change everything with the codes to be able to work under hostgator?

HostGator
No worries.

Some of these comments are from people who are using the HostGator form we offer, but your web designer will be able to easily use custom forms with HostGator.

MysticMike
How do I send the same form to multiple email address? Can I just repeat the
<input type="hidden" name="recipient" value="info@adomainname.com" />
line?
Thanks

HostGator
No, doing that will break the form.

Instead, just replace the one email with a list of multiple emails separated by commas. Here is my example:

<input type="hidden" name="recipient" value="myemail@mydomain.com,yours@mydomain.com,another@mydomain.com">

Kelly Kennedy
I have added a template to my website. I am not able to modify the source to add the form's functions. Does anyone know how to modify one of host gator's templates so the form will work and send the content to my email address?

HostGator
Well, yes you are able to modify the source. Otherwise, you couldn't customize the template at all. You need to edit the source code and copy&paste the part of the form code you want.

NOTE: Customizable templates require some HTML or Flash design experience. When adding this form to your existing site, you may not want to copy the entire code. Beginners should use a Site Builder program, instead.

Matt
I setup a form on my site and when it's emailed to me it's from: xxxxx@gatorxxx.hostgator.com. How can I make it from the site's name and not my cPanel url?

HostGator
You cannot control that setting on the CGI form we provide.

If you have a custom PHP form, you need to read the related article "How to use sendmail with PHP".

M.T.
What is the code I need to enter in order to show a custom "thank you" page to the form submitter after they click the submit button? Currently I have the following but it does not work:

<input type="hidden" name="redirect" value="submitted.htm">

Also is there a particular place this needs to appear within the form? I currently have it in the line with the form action tag, after the subject of the email tag.

HostGator
Everything sounds correct, but remember the redirect page is relative to the contact page. That means, the way you coded it, the contact form page must be in the same folder as the submitted.htm page.

Also, make sure the file is exactly spelled "submitted.htm" and not "submitted.html" or "submitted.Htm".

Our template suggests using the full URL (http://domain.com/submitted.htm). This may be the best solution because the relative path will not be assumed by the browser.

Amber
I have a question about having a form link to a submitted.html page. The end of my php code looks like this:

$sentOk = mail($to,$subject,$message,$headers);

echo "sentOk=" . $sentOk;

When I did a test, it sent me the email from the form but it just went to a white page that said "sentOK=1" at the top. I want it to go to a page titled "submitted.html" which is in the same folder as the page with the contact form and PHP forms in it. How do I alter the ending of my PHP code so it will redirect to that page?

HostGator
Don't use Tony's code. It purposely does exactly what you described.

Instead, use the code sample I provided at the related article "How to use sendmail with PHP". The sample code there does what you want.

tims
I have added a template to my website. I am not able to modify the source to add the form's functions. Does anyone know how to modify one of host gator's templates so the form will work and send the content to my email address?

HostGator
Easiest way is to use your control panel's File Manager to Edit the file.

Otherwise, download the file and edit it in Notepad or an HTML editor (like Dreamweaver or FrontPage).

Sean
I am trying to create a form, where simply the information entered in the text boxes takes the submit button and it goes directly to my email, not the old boring mailto form. I am putting it into flash also. Any help and advice is greatly appreciated.

Thanks,

Sean

HostGator
Read the related article, "How to use sendmail with PHP".

lim
Hi.. i'm creating a form , linking with Mysql in Cpanel.. 1 of my field is Email .. what should i do to state that this field must be fill up in the email add format? such as abc@gmail.com?? to prevent people from just filling up as abc. thanks

HostGator
If you go to the tutorial page (first link in this article), then you will find a Javascript Validated version of the email form. This one does exactly what you want.

If you want to create your own PHP form, then you can find the answer in our related article "How to use sendmail with PHP".

runescape money making skill
Many thanks for sharing your thoughts here. I really like it.

sdfsdgfd
Thanks For This Blog, was added to my bookmarks.

zydecotech
I'm using this code to enable an upload of a document using a form. The form works but the email does not have the document attached. Does your formmail support this? Is there something I'm missing in the code?

<p><i class="form">Attach signed patient authorization below <br>(PDF, Microsoft Word or JPEG):<br><input type="file" name="FileAuthorization" ></p><p>&nbsp;</p>

zydecotech
I'm using this code to enable an upload of a document using a form. I would like for the email response to me to have the document attached. The form works but the email does not have the document attached. The doc is re-named and stored in a tmp directory on the host. Does your formmail support this? Is there something I'm missing in the code?

<p><i class="form">Attach signed patient authorization below <br>(PDF, Microsoft Word or JPEG):<br><input type="file" name="FileAuthorization" ></p>

MarioP
I just want to tell you that your site is incredible, i love to read support.hostgator.com !

HostGator
Thank you for your comments. Just a quick reminder that the comments on this page are not monitored by technical support staff, and that for support issues, it is best to contact us by live chat, phone or email so we can assist you right away.

Although comments are not monitored by technical support staff, they are moderated and read by technical writers. Comments will need to be approved by a moderator before appearing.

Our technical writers do read the comments periodically for the purposes of updating the articles, and do appreciate your feedback, suggestions and corrections to the articles themselves, as well as any suggestions or tips for readers of this article. However, support questions posted here are not guaranteed to be replied to in a timely manner or at all. For support issues, it is best to contact our support staff instead by live chat, email or phone.



Your comments help us keep the knowledge base updated. This is not a medium for support. If you have questions or need help, please contact us via email, phone or live chat for fast assistance.

Post Comment