Support » Plugin: WP Mail SMTP by WPForms » Update to 1.5.0 messed up wp_mail when looping through users.

  • Resolved kevinstalder

    (@kevinstalder)


    We created some custom code to loop through users and send an email out to them when a post is published. Very simplistically we are running get_users( $args ); and are looping through those users and sending email via wp_mail();. When doing this it would loop through all 200 users but it would only send out an email to the first person in the array. So the first email address got 200 of the same emails. Reverting back to version 1.4.2 fixed this issue. So something in 1.5 seems to have broken it.

    Any idea what could have been the issue?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Jared Atchison

    (@jaredatch)

    Happy to investigate!

    Can you tell us what you plugin/mailer settings are (sensitive details omitted).

    Also can you share you custom code?

    These details will assist us with debugging and troubleshooting 🙂

    Seeing very odd behavior with 1.50, similar to the above.. In Gravity Forms, I’d setup two different notifications to go out for a form submit. With 1.50, the first notification gets sent twice, and the second one never gets sent at all.

    Thread Starter kevinstalder

    (@kevinstalder)

    We are using Sendgrid for the mailer and it is via the API Key.

    We determined it was the sending portion that was breaking it. (we did printed out the email before we did wp_mail and after and it was correct so it seemed to be something related to the actual wp_mail that didn’t work)

    This gets the users based on role and a custom post meta.

    $args = array();
        $args['role__not_in'] = array('pending', 'customer', 'subscriber');
        
        if( $role != null ) {
          $args['role__in'] = $role;
        }
    
        if( ( $_POST['post_security'] === 'checked' || get_post_meta( $this->post->ID, 'post_security', true ) === 'checked' ) && $role === null ){
          $sendto = array_merge(SUPPORT, array('administrator') );
          $args['role__in'] = $sendto;
        }
     return get_users( $args );

    This is the code to loop through users and sends the email.

    foreach( $this->users as $user ){
          $test = '';
          $test .= '<div>To: ' . $user->user_email . '</div>';
          $test .= '<div>Subject: ' . $this->subject . '</div>';
          $test .= '<div>Message: ' . $this->message . '</div>';
          $test .= '<div>Headers: ' . print_r($this->headers, true) . '</div>';
          // return $test;
          wp_mail( 
            $user->user_email,
            $this->subject,
            $this->message,
            $this->headers
          );
        }

    Might be related to this issue which has been identified for fix:

    https://github.com/awesomemotive/WP-Mail-SMTP/issues/55

    Plugin Author Slava Abakumov

    (@slaffik)

    Hi,

    I apologize for the trouble caused by this.

    The issue has been fixed on our latest version 1.5.1. Please update the plugin and let us know if you have any further issues.

    Have a good one!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Update to 1.5.0 messed up wp_mail when looping through users.’ is closed to new replies.