2012-02-16 23:46
浏览 54


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

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'); ?>
get_header(); ?>
echo do_shortcode( '[contact-form-7 id="23" title="Contact form 1"]' );

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

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

<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;">
        <label for="name">name</label>
        <input type="text" name="name" id="name" />
        <label for="email">email</label>
        <input type="text" name="email" id="email" />
        <label for="message">message</label>
        <textarea name="message" id="message" style="width:250px; height:100px"></textarea>
    <input type="submit" value="go" />

<?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 = "";

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

    if($success) {
        $_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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题