doudao7511
2012-02-16 23:46
浏览 54
已采纳

尝试在wordpress中使用php创建联系表单

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

<?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.";
    }
}
?>
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dounai9592 2012-02-17 00:50
    已采纳

    Why are you using CF7 and creating your own form at the same time? CF7 does all the processing for you.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题