I am having some trouble with Timo's "Web Mailer" script that was in the tutorials section. I have no idea how to work PHP, so go ahead and laugh when you see what I am trying to do. Well, here is what I have;
CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<script language="JavaScript" type="text/javascript">
function check(form){
if (form.name.value == "") {
alert("Please enter your name.");
form.name.focus();
return false;
}
else if (form.email.value == "") {
alert("Please enter your email.");
form.email.focus();
return false;
}
else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value))){
alert("Please enter a valid email address.");
form.email.focus();
return false;
}
else if (form.comment.value == "") {
alert("Please enter a comment/question.");
form.comment.focus();
return false;
}
else{
return true;
}
}
</script>
<?php
function mailcheck($emailadr){
return eregi("^[a-zA-Z0-9_\.-]+@[a-zA-Z0-9\.-]+\.[a-zA-Z]{2,4}$", $emailadr);
}
if (!isset($_POST['submit']))
#if submit doesn't have a value
{
?>
<h3>Feel free to contact me.</h3>
<form method="post" name="emailform" action="<?php echo $_SERVER['SCRIPT_NAME']?>" onSubmit="return check(this);">
<p>Name : <input type="text" name="name" /></p>
<p>Email : <input type="text" name="email" /></p><br />
<p>Comments/Questions : <br /><textarea name="comment" rows="10" cols="30"></textarea></p>
<p><input type="submit" name="submit" value="Submit" /></p>
</form>
<?php
}
else
{
$name = $_POST['name'];
$email = $_POST['email'];
$comment = stripslashes($_POST['comment']);
$to = "EMAIL LEFT OUT ";
if ((mailcheck($_POST['email']))||($comment!=NULL)||($name!=NULL))
#check if a real email address, if it returns true it sends the email
#also checks to make sure the comment and name fields aren't empty
{
# subject
$subject = "Mail from site.";
# message
$message = '
<html>
<head>
<title>Mail from site</title>
</head>
<body>
<p>The email contains user comments.</p>
<br />
Name of person : '.$name.'<br /> #I have it displaying the name
Email of person : '.$email.'<br />#here the email
Comment/Question left:<br />
<p>'.$comment.'</p>#here the comment
<br />
#it uses html so feel free to format to your pleasure
</body>
</html>
';
$headers = "MIME-Version: 1.0\r\n"; #headers
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $email>\r\n"; #The sender's email
#Will show up in your box from their email address
#mail it
mail($to, $subject, $message, $headers);
echo 'Thank you for sending mail.';
}
else {
echo 'Sorry, one of more or your fields is invalid.';}
}
?>
</body>
</html>
Anyways, it dosen't work. I am sure something is wrong. I am pretty sure that the php code has to be saved externally, but I don't know how to do that, or how to reference it. If someone could tell me what I have done wrong, that would be much appreciated.
thanks in advanced,
Chris