while (true) { $oldattachck = $oldattach . 'ck'; // Only add if it is checked if (isset($form->{$oldattachck}) and $form->{$oldattachck}) { $attachments[] = $form->{$oldattach}; } $i++; $oldattach = "oldattachment{$i}"; if (empty($form->{$oldattach})) { break; } } $email->set_oldattachments($attachments); } // Add body $email->set_body($form->body); // Add users sent mail if (isset($form->to)) { $email->set_sendusersbyto($form->to); } if (isset($form->cc)) { $email->set_sendusersbycc($form->cc); } if (isset($form->bcc)) { $email->set_sendusersbybcc($form->bcc); } // Add type action and if corresponding old mail id. $email->set_type($form->action); $email->set_oldmailid(isset($form->oldmailid) ? $form->oldmailid : NULL); $email->set_mailid(isset($form->id) ? $form->id : NULL); // Add new mail, in the Inbox or corresponding folder