This might seem like such an amateur thing, but I am an amateur when it comes to php...
Basically a website I'm creating for an organisation I'm a part of needs a contact form, because I'm always trying to learn I'd prefer to have made the code myself rather than just get some plugin. However my code doesn't quite seem to work.
Also first post, I'm pretty sure this isn't a duplicate due to it being different code, I have been using posts on this site to try get it to work but no luck, so thought best to post my code and hopefully people with more brain cells than me can help
Here's the html for the page itself:
<form method="post" action="contactengine.php">
<label for="Name"><h2>Your Name:</h2></label>
<input type="text" name="Name" id="Name" placeholder="Please Enter Your Name"/>
<label for="Email"><h2>Your Email:</h2></label>
<input type="email" name="Email" id="Email" placeholder="Please Enter Your Email Address"/>
<label for="Message"><h2>Message:</h2></label><br />
<textarea name="Message" rows="20" cols="20" id="Message"></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
The PHP:
<?php
$EmailFrom = "webmaster@temporary.co.uk";
$EmailTo = "webmaster@temporary.co.uk";
$Subject = "Contact Form Submission";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
I feel quite stupid because there's loads of literature on creating working contact forms but none of them seem to work
I'm hosted on 1and1 if that makes any difference?
Thanks in advance
EDIT: Okay I forgot to mention the problem: emails just aren't delivering, so I don't actually know if success is working or not, I've tried different email addresses, checked spam the whole shabang - so I'm struggling to work out what's going wrong on it