tonyf
tonyf

Reputation: 35557

How to implement a Contact Us form in my HTML site?

I am looking for a means of implementing a "Contact Us" routine/page that I can apply to my site that is purely a HTML website only.

I am assuming this will need to be a PHP process to send emails from a Contact Us form, but I am unsure how to do it.

Upvotes: 0

Views: 4772

Answers (4)

JCD
JCD

Reputation: 2231

As you said you were interested in looking into PHP, you could do this with one script (say, for example, Contact.php). In your Contact.php file you would put a simple HTML form with room for name, email address, short message, etc. This form can just submit the form data to the same page, process the data, and send out an email with PHP's mail() function. Doing it this way avoids the need to display your email address to the world.

Something simple like the following should get you started, although you are going to want to check any and all user input before mailing it to yourself!

<html>
<body>

<?php
// if the form was filled out and submitted, mail it
if ( isset($_REQUEST['subButton']) )
{
    $email = $_REQUEST['email'] ;
    $subject = "Contact Us request from site";
    $message = $_REQUEST['message'] ;
    mail( "[email protected]", "Subject: $subject", $message, "From: $email" );
    header("location: contact.html");
}
else
{
    echo "<form method='post' action='Contact.php'>
    Email: <input name='email' type='text'/><br/>
    Message:<br/>
    <textarea name='message' rows='10' cols='30'>
    </textarea><br/>
    <input type='submit' name='subButton' value='Contact Us'/>
    </form>";
}
?>

</body>
</html> 

Upvotes: 1

Xavias
Xavias

Reputation: 170

Mailto links are very insecure. expect to get spam up the wazoo.

Instead use javascript to simply mask it.

Put this where you want the link to be setup

var mailE1 = "contact"; var mailE2 = "yoursite.com"; var linktext = "Email Us"; document.write("" + linktext + "")

Upvotes: 0

Jerod Venema
Jerod Venema

Reputation: 44632

Since you're pure HTML now, I'm assuming you're trying to keep this simple?

Use a service.

Upvotes: 2

D&#39;Arcy Rittich
D&#39;Arcy Rittich

Reputation: 171421

The easiest way is to just use a mailto: link.

<a href="mailto:[email protected]?subject=Contact%20Us">Contact Us</a>

Upvotes: 1

Related Questions