/** * Look if the information in $input is ok to send. * If yes, send and return a confirmation. * Otherwise, return an array that tells what is missing. * * required information in $input: * sender_id, receiver_id, text * * optional fields in $input: * reply_to_id, draft_id * * @param unknown_type $input */ public function sendOrComplain($input) { // check fields $problems = array(); // Maximum 50 emails can be send using the Invitation-Form if (isset($_SESSION['InviteCount']) && $_SESSION['InviteCount'] > 50) { $problems['email'] = 'You already sent more than 50 invitations. Maybe that is enough for now?'; } elseif (!isset($input['email'])) { // $problems['receiver'] = 'no receiver was specified.'; // receiver does not exist. $problems['email'] = 'No receiver set.'; } else { // receiver is set, let's check the email addresses: $input['email'] = strtolower($input['email']); $input['email'] = str_replace(';', ',', $input['email']); $input['email'] = str_replace(' ', '', $input['email']); $email_array = explode(',', $input['email']); foreach ($email_array as $email) { if (!isset($email) || !$this->isEmailAddress($email)) { $problems['email'] = 'no correct email addresses.'; } } } if (!isset($input['sender_id'])) { // sender is not set. $input['sender_id'] = $_SESSION['IdMember']; // $problems['sender_id'] = 'no sender was specified.'; } else { if (!$input['sender_id'] != $_SESSION['IdMember']) { // sender is not the person who is logged in. $problems['sender_id'] = 'you are not the sender.'; } } if (empty($input['text'])) { $problems['text'] = 'text is empty.'; } $input['status'] = 'ToSend'; if (!empty($problems)) { $status = false; } else { // set the sender // FIXME: Read & Uncrypt member's email address from the DB and make it the sender-address //$sender_uncrypted = new MOD_member()->getFromMembersTable('email'); $member = $this->createEntity('Member')->findById($_SESSION['IdMember']); $sender = MOD_crypt::MemberReadCrypted($member->Email); //$sender = PVars::getObj('syshcvol')->MessageSenderMail; $result = MOD_mail::sendEmail($input['subject'], $sender, $email_array, false, $input['text']); //Now check if Swift actually sends it if ($result) { $status = true; $_SESSION['InviteCount'] = isset($_SESSION['InviteCount']) ? $_SESSION['InviteCount'] + count($email_array) : count($email_array); } else { MOD_log::write("MOD_mail: Failed to send a mail to " . implode(',', $email_array), "MOD_mail"); $problems['notsend'] = 'InviteNotSent'; $status = false; } } return array('status' => $status, 'problems' => $problems); }