Forum Moderators: open
I have had a go at building it (with Dreamweaver) but don't know how to design it so that when a potential student presses SUBMIT, the form will arrive in my email inbox. Any ideas?
Hope that makes sense!
<?phpif ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = htmlentities($_POST['name']);
$email = htmlentities($_POST['email']);
$comment = htmlentities($_POST['comment']);
$subject = 'Website contact from ' . $name . ' (' . $email . ')';
$sent = mail("example@example.com", $subject, $comment, $email);
}
?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Contact me</title>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
echo ('<form action="');
echo $_SERVER['PHP_SELF'];
echo ('" method="post">');
echo ('<fieldset><label for="name">Name:</label><input type="text" id="name" name="name" />
<label for="email">Email:</label><input type="text" id="email" name="email" />
<label for="comment">Comment:</label><textarea id="comment" name="comment" rows="4" cols="20"></textarea>
<input type="submit" value="Submit" class="submit" />
</fieldset>
</form>');
}elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($sent == 'TRUE') {
echo ('<p>Thanks! Your message has been successfully sent.</p>');
}
elseif ($sent == 'FALSE') {
echo ('<p>There was a problem sending your mail. Try contacting me directly at <a href="mailto:example@example.com">example@example.com</a>.</p>');
}
}
?>
</body>
</html>
It's pretty selfcontained: if the page is being requested normally then it writes out a form, but if it's being submitted to then it sends the mail and writes out a thankyou.
(n.b. my PHP skills are limited at best, so if anyone else wants to debug this go ahead. It seems to work for me though)
Are you using a third party host? Many commercial services today have a generic form set-up that you can just tweak to your own particular needs -- bypassing the issue of writing your own script. If you are on a commercial web host, it would be good to ask.
Mail scripts are usually written in PERL or PHP -- but many hosts already have it working on their server. So they can give you simple instructions on how to adapt the basic setup and you can bypass the learning curve.