0

I created a button on a User's page. It sends an alert email to the admin.

It was sending the same email to me 5 times... but I have made some changes. Now it is sending the same email twice.

I have searched around on this issue... there are lots of topics on wordpress emails sending twice but nothing with code similar to mine:

function confirmemailsent($atts, $content = null) {
global $wpdb;
global $current_user, $user_login;
        get_currentuserinfo();

$postcode = $_POST['button'];

if ( isset($postcode) ) {  
              $sendto = 'example@email.com';
        $sendfrom = 'example@email.com';
        $subject = "Subject";  
    $msg =  " ".$current_user->user_nicename."
".$current_user->user_mailaddress."
".$current_user->user_email."
".$current_user->display_name."";

  if (wp_mail($sendto, $subject, $msg)==true)
    {
        $message = 'Email Sent!';
    }
    else
    {
        $message = 'Email Failed';
    } 
}
return $message;
    }
add_shortcode('emailsentmessage_shortcode', 'confirmemailsent');

As you can see, I wanted to display a confirmation message once the User clicks the button. If I remove that shortcode and just did add_action('init','confirmemailsent'); then it just sends one email! Perfect!

But I want this shortcode... and it is sending duplicate emails to the admin.

Any ideas?

1
  • I'd guess (as the deleted answer suggested) that some plugin you have is processing the page body a second time, and so this shortcode is being run twice. If you do want to restrict this to a shortcode, i.e. so that the button is only registered on the right page, you probably need a flag in the code to check if it's already been processed and not send a second email.
    – Rup
    Aug 19 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.