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.



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

Matt
You can just add this line to your form anywhere before the submit button:

<input type="hidden" name="required" value="field1,field2," />

and replace field1 and field2 with the names of your required fields.
You can have as many required fields as you like, just separate them with commas.

HostGator
Matt's suggestion will work, but the error handling is not very good.

I recommend using the script we created.

Gina
when i use this code and it is submitted, the first field shows up at the end. I am using it just as it is written, can't figure it out!

HostGator
The form will send you an email with the visitor's email address in the From header.

The "tell me" email content will appear in the body of the email message.

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 go daddy email

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.

ftorrents
I make an online form so visitors send me emails directly from my website using your Version 2 (Javascript Validation) example of code.
When visitors send their emails, they don“t know if the message was sent because there is not a message like "Your mail was sent succesfully" or something like that...
How can I include that kind of message in my website?

HostGator
This is why you get to choose the redirect URL. <input type="hidden" name="redirect" value="http://www.mydomain.com/path">

The redirect should take your visitor to a page that says "Your mail was sent successfully."

Then you can link or redirect from that page to anywhere on your site. For a delayed redirect, check out http://webstarthelp.com/forwards.html - How do I forward a visitor from one page to another?


If you have read our knowledge base and still have questions or need more information, please contact us via phone or live chat for immediate assistance.

Post Comment