Duetschpire
Duetschpire

Reputation: 167

Send function being called twice

I've tried searching the above and found similar results, but non that could fix my issue. I have a WP theme which includes a function to send private messages between users, the receivers get email notification that a private message was received. The problem is that the message is being sent twice, so is the email. I can see the message in the inbox and outbox twice as well.

here's the code, not sure what's causing the issue:

 <?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>

I've tried playing around with the last bit of the code by removing/adding the "//", some resulted in emails sent but not messages, some resulted in messages sent 4 times, but none fixed the issue either.

Thanks guys

Upvotes: 0

Views: 453

Answers (1)

Alex
Alex

Reputation: 132

Just wanted to let you know I've been struggling with the same problem for weeks now and have finally found the SOLUTION. In my case wordpress was sending an email twice and adding an extra unneeded blank row to the database. I finally found an answer that said it had to do with table or forms or otherwise just improper html code wich makes no sense but lo and behold once i deleted the tables from surrounding all the php it now works completely fine. I realize that in your case the table makes sense, but still I would highly suggest you try to rewrite it with divs. SOme other answers I found with this had to do with improper html and javascript as well as forms or divs not being closed properly. However I don't think the problem lies in improper html use, but since i haven't found a case where someone had this problem outside of wordpress it seems that it could be just some wordpress flaws with tables, as I checked my code many times and it seemed correct. Anyway Good Luck, Hopefully that helps.

Upvotes: 1

Related Questions