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

尝试在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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码