Body: <p>I've got an even notifier plugin I have been working on for a specific client project. Sending an email to a single address works fine, but when I loop through a table containing email addresses it is sending duplicate addresses.</p>
  
  <p>I have a global table field (adminEmails) which has two columns, one for a name and the other for an email address.</p>
  
  <pre><code>          $adminGlobal = craft()-&gt;globals-&gt;getSetByHandle('admin');
            foreach($adminGlobal-&gt;adminEmails as $key =&gt; $admin){
              $email-&gt;toEmail = $admin['emailAddress'];
              $body .= "Manager ".$manager-&gt;fullName." has submitted an event for approval.\n\n";
              $body .= "Start Date &amp; Time: ".$entry-&gt;eventStartDate-&gt;format('m/d/Y g:i A'). "\n\n";
              $body .= "House: ".$house-&gt;houseName."\n\n";
              $body .= "School: ".$college-&gt;collegeName."\n\n";
              $body .= $entry-&gt;url;
              $email-&gt;body = $body;
              if($email-&gt;toEmail != ""){
                craft()-&gt;email-&gt;sendEmail($email);
              }
            }
  </code></pre>
  
  <p>I have been testing with two email addresses and both addresses receive the same email twice. Not sure what could be causing this. I tried creating a new email model object inside each foreach loop but that didn't help either. Any ideas what's happening here?</p>
  
  <p>EDIT:</p>
  
  <p>If I dump $admin you see the following,</p>
  
  <pre><code>array
  (
  'col1' =&gt; 'John Doe'
  'col2' =&gt; 'some.email@gmail.com'
  'adminName' =&gt; 'John Doe'
  'emailAddress' =&gt; 'some.email@gmail.com'
  ) 0 array
  (
  'col1' =&gt; 'Andrew Clinton'
  'col2' =&gt; 'some.email@anecka.com'
  'adminName' =&gt; 'Andrew Clinton'
  'emailAddress' =&gt; 'some.email@anecka.com'
  ) 1
  </code></pre>
  
  <p>This is what I was expecting..so why is it sending the same email twice to both addresses?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-23T00:39:31.330Z
Comments.Text: If you `Craft::dump($key)` and `Craft::dump($admin)`, what do they look like?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-24T18:18:11.063Z
Comments.Text: @BradBell I added the Craft::dump.
Comments.UserDisplayName: Panda4Man
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-24T21:05:41.283Z
Comments.Text: I'd guess that loop is being triggered twice then.  Maybe it's inside an event that's getting fired multiple times?  You can always `Craft::log()` to help verify.
Comments.UserDisplayName: Brad Bell
Tags: <plugin-development><emails>
Title: Plugin Emails Being Sent Twice
ThreadText: # Plugin Emails Being Sent Twice
  
  (Asked by: username_0 on 2015-07-22)
  
  I've got an even notifier plugin I have been working on for a specific client project. Sending an email to a single address works fine, but when I loop through a table containing email addresses it is sending duplicate addresses.
  
  I have a global table field (adminEmails) which has two columns, one for a name and the other for an email address.
  
  ```
            $adminGlobal = craft()->globals->getSetByHandle('admin');
            foreach($adminGlobal->adminEmails as $key => $admin){
              $email->toEmail = $admin['emailAddress'];
              $body .= "Manager ".$manager->fullName." has submitted an event for approval.\n\n";
              $body .= "Start Date & Time: ".$entry->eventStartDate->format('m/d/Y g:i A'). "\n\n";
              $body .= "House: ".$house->houseName."\n\n";
              $body .= "School: ".$college->collegeName."\n\n";
              $body .= $entry->url;
              $email->body = $body;
              if($email->toEmail != ""){
                craft()->email->sendEmail($email);
              }
            }
  
  ```
  
  I have been testing with two email addresses and both addresses receive the same email twice. Not sure what could be causing this. I tried creating a new email model object inside each foreach loop but that didn't help either. Any ideas what's happening here?
  
  EDIT:
  
  If I dump $admin you see the following,
  
  ```
  array
  (
  'col1' => 'John Doe'
  'col2' => 'some.email@gmail.com'
  'adminName' => 'John Doe'
  'emailAddress' => 'some.email@gmail.com'
  ) 0 array
  (
  'col1' => 'Andrew Clinton'
  'col2' => 'some.email@anecka.com'
  'adminName' => 'Andrew Clinton'
  'emailAddress' => 'some.email@anecka.com'
  ) 1
  
  ```
  
  This is what I was expecting..so why is it sending the same email twice to both addresses?
  
  **Tags:** plugin-development, emails
  
  > **Comments:**
  > **username_1**: If you `Craft::dump($key)` and `Craft::dump($admin)`, what do they look like?  
  > **username_0**: @username_1 I added the Craft::dump.  
  > **username_1**: I'd guess that loop is being triggered twice then.  Maybe it's inside an event that's getting fired multiple times?  You can always `Craft::log()` to help verify.  
  
  ---
  
  ## 0 answers
  
  