Trying to create a contact form with php in wordpress

I have written code to submit a form and email in php and placed it in my wordpress custom page. I have included the php to send the email, but for some reason nothing gets sent. I am not sure where to start for debugging this thing.

Here is my code for the custom page

Read More
<?php
/*
Template Name: page-pickup.php
*/
?>
<?php include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); ?>
<?  include_once(ABSPATH. 'wp-content/themes/fiftyfityNew/contact-form.php'); ?>

<?php add_post_meta(7, 'fruit', 'banana', true) or update_post_meta(7, 'fruit', 'banana'); ?>
<?php
get_header(); ?>
<?php
echo do_shortcode( '[contact-form-7 id="23" title="Contact form 1"]' );
?>

<?php
    if(isset($GLOBALS["mail_message"])) {
        echo "<p>".$GLOBALS["mail_message"]."</p>";
    }

    if(isset($_SESSION["mail_message"])) {
        echo "<p>".$_SESSION["mail_message"]."</p>";
        unset($_SESSION["mail_message"]);
    }
?>

<form method="POST" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<input type="hidden" name="form-name" value="contact" />
<div style="text-align:left; border: 1px solid #bbb; padding:10px;">
    <div>
        <label for="name">name</label>
        <input type="text" name="name" id="name" />
    </div>
    <div>
        <label for="email">email</label>
        <input type="text" name="email" id="email" />
    </div>
    <div>
        <label for="message">message</label>
        <textarea name="message" id="message" style="width:250px; height:100px"></textarea>
    </div>
    <input type="submit" value="go" />
</div>
</form>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Here is my code for the included contact-form.php

<?
function send_message()
{
    $subject = "Test email form WordPress";
    $body = $_POST['message'];
    $recipient = "anderskitson@gmail.com";

    $success = @wp_mail($recipient, $subject, $body);

    if($success) {
        session_start();
        $_SESSION["mail_message"] = "Thank you. your message has been sent.";
        header( 'Location:  '.$_SERVER['HTTP_REFERER'] ) ;
    }
    else {
        $GLOBALS["mail_message"] = "Euston, we have a problem.";
    }
}
?>

Related posts

Leave a Reply

1 comment