hope things are going well.
I'm attempting to add a custom contact form to a section of home page. I came across a custom contact form at https://gist.github.com/hansspiess/6815875. I implemented the code into my home page to utilize the custom styling of the Zurb Foundation based theme I'm using. The form seems to be validating correctly and providing the appropriate error messages. Upon a "successful" submission, I receive a success alert, but am NOT actually receiving an e-mail at the admin e-mail address. I have also attempted to manually insert alternative email addresses in my $mailto variable. My hopes are that I may be missing some obvious, any help would greatly be appreciated.
My site is ajinin.com
Here is the php logic that I've placed above <?php get_header(); ?>
:
<?php
/* response strings */
$missing_fields = 'Please fill out all fields.';
$email_invalid = 'Your e-mail address is invalid.';
$trapped = 'Please do not call this page via scripts.';
$error = 'The message could not be sent.';
$success = 'Thank you! The message has been sent';
/* process post vars, leave honeypot raw */
$submitted = sanitize_text_field( $_POST['scf_submitted'] );
$name = sanitize_text_field( $_POST['scf_name'] );
$email = sanitize_text_field( $_POST['scf_email'] );
$message = sanitize_text_field( $_POST['scf_message'] );
$honeypot = $_POST['scf_message2'];
/* wp_mail vars */
$mailto = get_option( 'admin_email' );
$subject = 'Message from ' . get_bloginfo('name');
$headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n";
if ( $submitted ) {
if ( $honeypot != "" ) {
scf_response("alert-danger", $trapped);
} else {
if ( !$name || !$email || !$message ) {
$alert[] = $missing_fields;
}
if ( !is_email( $email ) && $email ) {
$alert[] = $email_invalid;
}
if ( empty( $alert ) ) {
if ( wp_mail( $mailto, $subject, strip_tags( $message ), $headers ) ) {
$alert[] = $success;
scf_response("success", $alert);
unset( $submitted, $name, $email, $message, $honeypot );
} else {
$alert[] = $error;
scf_response("alert", $alert);
}
} else {
scf_response("warning", $alert);
}
}
}
/* output alert html */
function scf_response( $class, $alertArr ){
global $response;
$alertStr = implode( '<br>', $alertArr );
$response = '<div data-alert class="alert-box ' . $class .'">' . $alertStr . '<a href="#" class="close">×</a></div>';
}
?>
Here is the html form:
<div class="grey">
<div class="row">
<div class="large-10 columns small-centered">
<h5>QUESTIONS OR COMMENTS? LET US KNOW.</h5>
<br>
<div class="row">
<div class="large-12 columns">
<?php echo $response ?>
</div>
</div>
<form role="form" action="<?php the_permalink(); ?>" method="post">
<div class="row">
<div class="large-6 columns">
<label for="scf_name" class="contact">Name</label>
<input
type="text"
id="scf_name" name="scf_name"
value="<?php echo $name; ?>">
</div>
<div class="large-6 columns">
<label for="scf_email" class="contact">Email</label>
<input
type="text"
id="scf_email" name="scf_email"
value="<?php echo $email; ?>">
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label for="scf_message" class="contact">Message</label>
<textarea
rows="4"
id="scf_message" name="scf_message"><?php echo $message; ?></textarea>
</div>
</div>
<div class="row" style="display:none">
<div class="large-12 columns">
<label for="scf_message2" class="contact">message2</label>
<input type="text" name="scf_message2" name="scf_message2">
</div>
</div>
<div class="row text-center">
<div class="large-12 columns">
<input type="hidden" name="scf_submitted" value="1">
<button type="submit" class="button medium blue">Send</button>
</div>
</div>
</form>
</div>
</div>
</div>
Thank for any help that can be provided. If someone has an alternative method or know of a tutorial for a custom contact form they trust, please let me know. The most important thing for me is that I can finely control the html/css structure.