I'm making a website and i want to send the values inputed into a contact form directly to my email. I already have a php script for it but it never sends any email any help will be greatly appreciated. the html form:
<form role="form" id="contactForm" class="contact-form" data-toggle="validator" class="shake">
<div class="col-sm-7 slideanim" method="post" action="php-core/mail-core.php">
<div class="row">
<div class="col-sm-6 form-group">
<div class="controls">
<input class="form-control" id="name" name="name" placeholder="Name" type="text" required required data-error="Please enter your name">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6 form-group">
<div class="controls">
<input class="form-control" id="email" name="email" placeholder="Email" type="email" required required data-error="Please enter your email">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6 form-group">
<div class="controls">
<input type="text" id="msg_subject" class="form-control" placeholder="Subject" required data-error="Please enter your message subject">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6 form-group">
<div class="controls">
<input class="form-control" id="phone" name="phone" placeholder="Phone Number" type="tel" required required data-error="Please enter your Phone Number">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="form-group">
<div class="controls">
<textarea class="form-control" id="message" name="message" placeholder="Message" rows="5" required data-error="Write your message"></textarea><br>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="row">
<div class="col-sm-12 form-group">
<button class="btn btn-default pull-right" type="submit" id="submit">Send</button>
<div id="msgSubmit" class="h3 text-center hidden"></div>
<div class="clearfix" style="padding-bottom: 20px;"></div>
</div>
</div>
</div>
</form>
the php script:
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = $_POST['name'];//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user:- \n\nName: $name \n".
"Email Address: $visitor_email \n".
"Message: $message \n";
$to = "Sparkidea1@yahoo.com";//<== update the email address
$from = "Reply-To: $visitor_email";
$headers .= "\r\n Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$from);
//done. redirect to thank-you page.
header('Location: bat/thank-you.html');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
it doesn't give errors but it does not send mails help please...thanks!