【问题标题】:Send function being called twice发送函数被调用两次
【发布时间】:2013-09-18 19:28:04
【问题描述】:

我已尝试搜索上述内容并找到了类似的结果,但无法解决我的问题。我有一个 WP 主题,其中包括在用户之间发送私人消息的功能,接收者会收到收到私人消息的电子邮件通知。 问题是消息被发送了两次,电子邮件也是如此。我也可以在收件箱和发件箱中看到两次消息。

这是代码,不知道是什么导致了问题:

 <?php }

     elseif($third_page == 'send') { ?>
    <?php

        $pid = $_GET['pid'];
        $uid = $_GET['uid'];

        $user = get_userdata($uid);

        if(!empty($pid))
        {
            $post = get_post($pid);
            $subject = "RE: ".$post->post_title;
        }



        if(isset($_POST['send']))
        {
            $subject = strip_tags(trim($_POST['subject']));
            $message = strip_tags(trim($_POST['message']));
            $to = $_POST['to'];

            if(!empty($to))
            {
                $uid = auctionTheme_get_userid_from_username($to);  
            }

            if($uid != false && $current_user->ID != $uid):

            global $current_user;
            get_currentuserinfo();
            $myuid = $current_user->ID;

            global $wpdb; $tm = current_time('timestamp',0);        
            $s = "insert into ".$wpdb->prefix."auction_pm (subject, content, datemade, pid, initiator, user) values('$subject','$message','$tm','$pid','$myuid','$uid')";
            //mysql_query($s) or die(mysql_error());        
             // $wpdb->show_errors     = true;
            $wpdb->query($s);
            //echo $wpdb->last_error;
        //-----------------------

            $user = get_userdata($uid);
            AuctionTheme_send_email_on_priv_mess_received($myuid, $uid)

        //-----------------------       
            ?>

            <div class="my_box3">
            <div class="padd10">
             <?php _e('Your message has been sent.','AuctionTheme'); ?>
            </div>
            </div>

            <?php
            elseif($current_user->ID == $uid): 
            ?>

                <div class="error">             
             <?php _e('Cant send messsages to yourself','AuctionTheme'); ?>               
            </div>


            <?php
            else:
            ?>

            <div class="my_box3">
            <div class="padd10">
             <?php _e('The message was not sent. The recipient does not exist.','AuctionTheme'); ?>
            </div>
            </div>


            <?php
            endif;
        }
        else
        {


    ?>   

    <div class="my_box3">
            <div class="padd10">

            <div class="box_title"><?php echo sprintf(__("Send Private Message to: %s","AuctionTheme"), $user->user_login); ?></div>
            <div class="box_content">  
            <form method="post" enctype="application/x-www-form-urlencoded">
            <table>
            <?php if(empty($uid)): ?>
            <tr>
            <td width="140"><?php _e("Send To", "AuctionTheme"); ?>:</td>
            <td><input size="20" name="to" type="text" value="" /></td>
            </tr>
            <?php endif; ?>

            <tr>
            <td width="140"><?php _e("Subject", "AuctionTheme"); ?>:</td>
            <td><input size="50" name="subject" type="text" value="<?php echo $subject; ?>" /></td>
            </tr>

            <tr>
            <td valign="top"><?php _e("Message", "AuctionTheme"); ?>:</td>
            <td><textarea name="message" rows="6" cols="50"></textarea></td>
            </tr>

             <tr>
            <td width="140">&nbsp;</td>
            <td></td>
            </tr>

             <tr>
            <td width="140">&nbsp;</td>
            <td><input name="send" type="submit" value="<?php _e("Send Message",'AuctionTheme'); ?>" /></td>
            </tr>

            </table>
            </form>

            </div>
            </div>
            </div>


    <?php } } ?>

</div>

我尝试通过删除/添加“//”来处理代码的最后一点,有些导致发送了电子邮件但没有发送消息,有些导致发送了 4 次消息,但也没有解决问题。

谢谢大家

【问题讨论】:

  • send 函数在哪里被调用?我在您的代码中没有看到对该函数的任何引用。
  • 抱歉,更新了代码。希望够了吗?

标签: php wordpress function email send


【解决方案1】:

只是想让您知道,我已经为同样的问题苦苦挣扎了好几个星期,终于找到了解决方案。 在我的情况下,wordpress 发送了两次电子邮件,并向数据库添加了一个额外的不需要的空白行。我终于找到了一个答案,说它与表格或表格有关,或者只是 不正确的 html 代码 这没有任何意义,但是一旦我从周围 删除表格它现在所有的 php 都可以正常工作。我意识到在您的情况下该表是有道理的,但我仍然强烈建议您尝试用 div 重写它。我发现的其他一些答案与不正确的 html 和 javascript 以及未正确关闭的表单或 div 有关。 但是我不认为问题出在不正确的 html 使用上,但由于我没有发现有人在 wordpress 之外遇到这个问题的情况,它似乎可能只是一些 wordpress 的表格缺陷 ,因为我多次检查我的代码,它似乎是正确的。 无论如何祝你好运,希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-03
    • 2013-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-15
    • 2019-03-03
    • 2015-02-25
    相关资源
    最近更新 更多