title: email body appears multiple times
body: <p>I'm trying to send a small batch of emails in a loop using PHP mail(). The script to send the emails works fine. There is, however, a slight glitch. Whilst the recipients all receive only one email, the first person on the list receives the email body ($MESSAGE_BODY) once, the second person gets the body twice and the third person gets it 3 times (and on it goes). I cannot for the life of me work out why it's doing it.</p>
  
  <p>The form from which the emails are sent is:</p>
  
  <pre><code>&lt;p&gt;Message Text:
  &lt;br /&gt;
  &lt;textarea name="thebody" id="thebody" cols="65" rows="12"&gt;&lt;?php echo $row_email['emailtext'];?&gt;&lt;/textarea&gt;
  &lt;script type="text/javascript"&gt;CKEDITOR.replace( 'thebody' );&lt;/script&gt;
  &lt;/p&gt;
  &lt;table &gt;
  &lt;tr&gt;
  &lt;th&gt;Site&lt;/th&gt;
  &lt;th&gt;Email Address&lt;/th&gt;
  &lt;th colspan="2"&gt;Email Now?&lt;/th&gt;
  &lt;/tr&gt;
  &lt;?php  
  $b = 0;
  $q = 1;
  while ($row_selfdo = mysql_fetch_assoc($selfdo)) {  ?&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;?php echo $row_seldo[‘sitename’];?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="emailto[]" style="font-size:9px;" size="20" value="&lt;?php echo $row_selfdo['eaddress']; ?&gt;"/&gt;&lt;/td&gt;
  
  &lt;td valign="middle"&gt;Yes:&lt;input type="radio" name="emailnow[&lt;?php echo $b;?&gt;]" value="Yes" &lt;?php if (isset($mailed) &amp;&amp; ($mailed=="Not Yet")) { echo ""; } else echo "disabled='disabled'"; ?&gt; /&gt;&lt;/td&gt;
  
  &lt;td&gt;No:&lt;input name="emailnow[&lt;?php echo $b;?&gt;]" type="radio" value="No" checked="checked"  &lt;?php if (isset($mailed) &amp;&amp; ($mailed=="Not Yet")) { echo ""; } else echo "disabled='disabled'"; ?&gt;? /&gt;&lt;/td&gt;
  
  &lt;/tr&gt;
  &lt;?php $b++; $q++; }  ?&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>And here's the script to send the mail</p>
  
  <pre><code>$numb = count($_POST['emailto']);
  $num = $numb -1;
  $subject=$_POST['subject'];
  $thisrecipient = $_POST['emailto'];
  $sendtothemnow = $_POST['emailnow'];
  
  for ($a=0;$a&lt;=$num;$a++) {
  
  $emailthemnow = $sendtothemnow[$a];
  
  
  if ((isset($emailthemnow))&amp;&amp;(($emailthemnow)=="Yes")) {
  
  $recipient = $thisrecipient[$a];
  $ToEmail = $recipient; 
  $EmailSubject = $subject; 
  $mailheader = 'From: me@mydomain.com'."\r\n"; 
  $mailheader .= 'Reply-To: me@mydomain.com'."\r\n";
  $mailheader .= 'MIME-Version: 1.0'."\r\n";
  $mailheader .= 'Content-type: text/html; charset=iso-8859-1'."\r\n"; 
  $MESSAGE_BODY .= '&lt;p&gt;'.$_POST['thebody'].'&lt;/p&gt;';
  $MESSAGE_BODY .= '&lt;p&gt;Kind Regards&lt;/p&gt;';
  $MESSAGE_BODY .= '&lt;p&gt;The Environment Team&lt;/p&gt;';
  $MESSAGE_BODY .= 'email footer bits here ';
  $MESSAGE_BODY .='&lt;p style="color:#0C0;"&gt;Please consider the environment - do you really need to print this email?';
  
  $MESSAGE_BODY=wordwrap($MESSAGE_BODY,70);
  
  $mailsent=  mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Not Sent");
  
      if($mailsent){
      //update a table to record date email was sent
      }
  }//end email send loop
  </code></pre>
  
  <p>Any suggestions??</p>
  
  <p>Many thanks in advance</p>