I've recently been trying to set up a simple Form-to-Email service within my website, but no matter how simple my code is - or even if i copy someone elses code, it never seems to implement properly.
For example -
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Form</title>
</head>
<body>
<form method="post" action="contact.php">
Email: <input name="email" type="text"><br>
Message:<br>
<textarea name="message" rows="15" cols="40"></textarea><br>
<input type="submit">
</form>
</body>
</html>Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$email_to = "somebody@email.com";
$email_subject = "Comment from Customer";
$email_body = $_POST['message'];
if(mail($email_to, $email_subject, $email_body)){
echo "The email($email_subject) was successfully sent.";
} else {
echo "The email($email_subject) was NOT sent.";
}
?>
</body>
</html>I plan to make something more complex than this, but I thoughtit best to figure out what is wrong first rather than jump head-first into a new language I seem to be struggling with. Just to be clear, the problem I have is that when I click the "submit" button, it redirects me to the page "contact.php" where all that is shown is a blank page, and no email is sent (i did change the "somebody@email.com" to my own email, which was a hotmail account, for convenience of testing) which I presume, means there is something wrong with my code.
Thanks,