This is my first post, hopefully there is a simple answer:
So as per the topic title, I cannot get my form to send an email.
This is the HTML code:
<form method="post" action="email.php">
<div class="row half">
<div class="6u"><input type="text" class="text" name="name" placeholder="Name" /></div>
<div class="6u"><input type="text" class="text" name="email" placeholder="Email" /></div>
</div>
<div class="row">
<div class="12u"><input type="text" class="text" name="subject" placeholder="Subject" /></div>
</div>
<div class="row half">
<div class="12u">
<textarea name="message" placeholder="Message"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<ul class="actions">
<li><input type="submit" value="Send Message" /></li>
<li><input type="reset" value="Reset" name="reset"/></li>
</ul>
</div>
</div>
</form>
Here is the PHP code:
<?php
//Required Input Fields
$name = check_input($_POST['name'], "<p>Please Enter Your Name!</p><p><a href='#' onclick='history.go(-1)' class='button style2 scrolly scrolly-centered'>Go Back</a></p>");
$email = check_input($_POST['email'], "<p>Please Enter Your Email Address!</p><p><a href='#' onclick='history.go(-1)' class='button style2 scrolly scrolly-centered'>Go Back</a></p>");
$subject = check_input($_POST['subject'], "<p>Please Enter a Subject!</p><p><a href='#' onclick='history.go(-1)' class='button style2 scrolly scrolly-centered'>Go Back</a></p>");
$message = check_input($_POST['message'], "<p>Please Enter Your Message!</p><p><a href='#' onclick='history.go(-1)' class='button style2 scrolly scrolly-centered'>Go Back</a></p>");
//Html Error
$SpamErrorMessage = "<p>No Website URLs Permitted!</p><br /><p><a href='#' onclick='history.go(-1)'>Go Back</a></p>";
if (preg_match("/http/i", "$name")) {echo "$SpamErrorMessage"; exit();}
if (preg_match("/http/i", "$email")) {echo "$SpamErrorMessage"; exit();}
if (preg_match("/http/i", "$subject")) {echo "$SpamErrorMessage"; exit();}
if (preg_match("/http/i", "$message")) {echo "$SpamErrorMessage"; exit();}
//Email Validation
$email = htmlspecialchars($_POST['email']);
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
{
die("<p>We're Sorry, Your Email Address Does Not Appear to Be Valid.</p><p><a href='#' onclick='history.go(-1)'>Go Back</a></p>");
}
//Function Check to Eliminate Unwanted Characters, Strips Quotes, and Adds HTMLSpecialCharacters
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
die($problem);
}
return $data;
}
//Sends Email and Forwards to Thank You Page
mail('*****@gmail.com', $subject, $message, '-f$email');
echo "<h2><p>Thank you for your message. <br /> We will reply back to you shortly.</h2><p><a href='http://www.*****.co.uk' class='button style2 scrolly scrolly-centered'>Click here to return</a></p>";
?>
Can anyone work out what could be wrong? The server that the code is running on does not have an SMTP server. Is this what could be causing the code to fail?
Thank You