0

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">&times;</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.

  • Is it being called correctly? Or is the conditional statement incorrectly not logical perhaps? – UkrVolk Feb 11 '14 at 4:05
  • According to the WP documentation, <?php the_permalink(); ?> needs to be within the loop. Currently. I don't have it in a loop as i may this page completely static. I'm going to try putting a loop into their and see what happens. – UkrVolk Feb 11 '14 at 4:14
  • Check your server logs. You say there is "no error". How are you checking for errors? Are you sure debugging is on? – s_ha_dum Feb 11 '14 at 4:30
  • I was able to access the log. Do you have any idea what type of message I'm looking for? – UkrVolk Feb 11 '14 at 4:47
  • Something referencing that line. Just try to send a message and then look at the last few lines of the log file. – s_ha_dum Feb 11 '14 at 4:52
0

So after some tinkering and research, this issue was coming from my host's anti-spam mail rules. The hosting service I'm using does not allow mail to be sent from anything other than the hosted email address. I ended up using Contact Form 7 plugin as it still allowed to implement the Zurb Foundation HTML markup. I'll to revisit this code when I have more time in the future. but I believe i could get it to work with a few adjustments. For my installment, i would need to override From: "Example User" <email@example.com> with my hosted email address, otherwise my host will block it as spam. Here is a link that contains some good instructions and troubleshooting for WP Contact Form 7.

http://cool-tricks.net/contact-form-7-configuration/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.