Web Hosting News, Web Hosting Tips, Web Hosting Tutorials and FAQ by AwardSpace.com
AwardSpace Blog » Archive of 'Jun, 2009'

Example contact form (form-to-mail). 5 comments

Our servers require SMTP authentication, which in plain English means you will have to use any of your e-mail accounts, created within the E-mail Manager -> E-mail Accounts section from your control panel.
You can see the code of an example contact form below(contact.html):

<html>
<head>
<title>
Contact form
</title>
</head>
<body>
<center>
<font size=”5″>
<b>
Contact form
</b>
<br>
<br>
</font>
<form method=”POST” action=”mailer.php”>
Subject:
<input type=”text” name=”subject” size=”20″>
<br>
<br>
Name:
<input type=”text” name=”name” size=”20″>
<br>
<br>
E-mail:
<input type=”text” name=”email” size=”20″>
<br>
<br>
Message:<br>
<textarea rows=”9″ name=”message” cols=”30″>
</textarea>
<br>
<br>
<input type=”submit” value=”Send” name=”submit”>
</form>
</center>
</body>
</html>

To have the form working you will also have to create a file called mailer.php with the below code:

<?php
if(isset($_POST['submit'])) {

$myemail = “youremail@yourdomain.com”;
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers = “From:Contact Form <$myemail>\r\n”;
$headers .= “Reply-To: $name <$email>\r\n”;

echo “Your message has been sent successfully!”;
mail($myemail, $subject, $message, $headers);

} else {

echo “An error occurred during the submission of your message”;

}
?>

If you already have a non-working contact form try adding the following variables and check if it works:

$mymail = “youremail@yourdomain.com”;
$headers = “From:Contact Form <$myemail>\r\n”;
$headers .= “Reply-To: $name <$email>\r\n”;
mail($mymail, $subject, $message ,$headers);

NOTE: The Reply-To header could be set with different variable than $email, depending on the contact form itself.

If your contact form already has the $header or $headers variable you will have to add the code with the following change:

$mymail = “youremail@account.com”;
$headers .= “From:Contact Form <$myemail>\r\n”;
$headers .= “Reply-To: $name <$email>\r\n”;
mail($mymail, $subject, $message ,$headers);

NOTE: The Reply-To header could be set with different variable than $email, depending on the contact form itself.

If you wish the messages from the contact form to be received in e-mail box which is not on our servers just replace the $mymail in the mail() function with the e-mail where the e-mails should be sent to.

Top of page / Subscribe to new Entries (RSS)