I've added a contact form to my site that just needs to send the $name, $email, and $drag in an email. I've tried to update my php.ini file with my smtp info, added the correct $header, and still don't receive the email. The below PHP code does show the success page, but i'm not getting the email. Any help appreciated(I'm a php noob)
My php:
<?php
if(isset($_POST['send'])) {
$to = "myemail@gmail.com";
$email_subject = "RSVP Form Data";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['drag']) ||
!isset($_POST['email'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name'];
$drag = $_POST['drag'];
$email_from = $_POST['email'];
$error_message = "";
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$drag)) {
$error_message .= 'The Name of your Drag does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Full Name: ".clean_string($name)."\n";
$email_message .= "Drag's Full Name: ".clean_string($drag)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
// create email headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: $email';
@mail($to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<div style="text-align:center;">
<p>Thank you for your RSVP. We'll see you there XX/XX/XXXX</p>
<p><a href="mydomain/wedding">Return to Our Wedding Home Page</a></p>
</div>
<?php
}
?>
my Form
<form id="contact" method="post" action="rsvp.php" class="form-horizontal" role="form">
<input type="name" name="name" class="form-control" id="name" placeholder="FULL NAME">
<br/>
<input type="email" name="email" class="form-control" id="email" placeholder="EMAIL ADDRESS">
<h4 class="h4">SELECT ONE</h4>
<div class="checkbox">
<label>
<input id="stag" type="checkbox"> STAG (GOING SOLO)
</label>
<p class="stag"><br><small> - SEE YOU THERE! -</small></p>
</div>
<br/>
<div class="checkbox">
<label>
<input id="drag" type="checkbox"> DRAG (+PLUS ONE)
</label><input type="drag" name="drag" class="form-control drag" id="drag" placeholder="DRAG'S FULL NAME">
</div>
<br>
<button class="btn btn-danger modalcancelbutton" role="button" data-dismiss="modal">CANCEL</button>
<input class="btn btn-primary send modalsendbutton" id="send" name="send" type="submit" value="SEND">
</form>