$filename = str_replace(" ", "_", "{$reportMaker->name}{$filenamestamp}.csv"); $fp = sugar_fopen(sugar_cached("csv/") . $filename, "w"); fwrite($fp, $csv); fclose($fp); $tempFiles[$filename] = $filename; } // get the recipient data... // first get all email addresses known for this recipient $recipientEmailAddresses = array($user->email1, $user->email2); $recipientEmailAddresses = array_filter($recipientEmailAddresses); // then retrieve first non-empty email address $recipientEmailAddress = array_shift($recipientEmailAddresses); // get the recipient name that accompanies the email address $recipientName = $locale->formatName($user); try { $mailer = MailerFactory::getMailerForUser($current_user); // set the subject of the email $subject = empty($reportMaker->name) ? "Report" : $reportMaker->name; $mailer->setSubject($subject); // add the recipient $mailer->addRecipientsTo(new EmailIdentity($recipientEmailAddress, $recipientName)); // add the attachments $tempCount = 0; foreach ($tempFiles as $filename) { $filePath = sugar_cached("csv/") . $filename; $attachmentName = "{$subject}_{$tempCount}.csv"; $attachment = new Attachment($filePath, $attachmentName, Encoding::Base64, "application/csv"); $mailer->addAttachment($attachment); $tempCount++; } // set the body of the email
function get_invite_email($focus, $admin, $address_array, $invite_person, $alert_msg, $alert_shell_array) { $type = "Custom"; if ($alert_shell_array['source_type'] == "System Default") { $type = "Default"; } $users = array(); $contacts = array(); $mailTransmissionProtocol = "unknown"; try { $mailer = MailerFactory::getMailerForUser($GLOBALS["current_user"]); $mailTransmissionProtocol = $mailer->getMailTransmissionProtocol(); //TO: Addresses foreach ($address_array['to'] as $userInfo) { try { // reuse the mailer, but process one send per recipient $mailer->clearRecipients(); $mailer->addRecipientsTo(new EmailIdentity($userInfo['address'], $userInfo['name'])); $possibleInvitee = populate_usr_con_arrays($userInfo, $users, $contacts); if ($possibleInvitee == true) { $userInfo['notify_user']->new_assigned_user_name = "{$userInfo['notify_user']->first_name} {$userInfo['notify_user']->last_name}"; $error = false; // true=encountered an error; false=no errors if ($type == "Default") { $error = get_system_default_body($mailer, $focus, $userInfo['notify_user']); } else { $error = create_email_body($focus, $mailer, $admin, $alert_msg, $alert_shell_array, $userInfo['notify_user']->id); } if ($error) { throw new MailerException("Failed to add message content", MailerException::InvalidMessageBody); } $mailer->send(); } } catch (MailerException $me) { $message = $me->getMessage(); $GLOBALS["log"]->warn("Notifications: error sending e-mail (method: {$mailTransmissionProtocol}), (error: {$message})"); } } //CC: Addresses foreach ($address_array['cc'] as $userInfo) { try { // reuse the mailer, but process one send per recipient $mailer->clearRecipients(); $mailer->addRecipientsCc(new EmailIdentity($userInfo['address'], $userInfo['name'])); $possibleInvitee = populate_usr_con_arrays($userInfo, $users, $contacts); if ($possibleInvitee == true) { $userInfo['notify_user']->new_assigned_user_name = "{$userInfo['notify_user']->first_name} {$userInfo['notify_user']->last_name}"; $error = false; // true=encountered an error; false=no errors if ($type == "Default") { $error = get_system_default_body($mailer, $focus, $userInfo['notify_user']); } else { $error = create_email_body($focus, $mailer, $admin, $alert_msg, $alert_shell_array, $userInfo['notify_user']->id); } if ($error) { throw new MailerException("Failed to add message content", MailerException::InvalidMessageBody); } $mailer->send(); } } catch (MailerException $me) { $message = $me->getMessage(); $GLOBALS["log"]->warn("Notifications: error sending e-mail (method: {$mailTransmissionProtocol}), (error: {$message})"); } } //BCC: Addresses foreach ($address_array['bcc'] as $userInfo) { try { // reuse the mailer, but process one send per recipient $mailer->clearRecipients(); $mailer->addRecipientsBcc(new EmailIdentity($userInfo['address'], $userInfo['name'])); $possibleInvitee = populate_usr_con_arrays($userInfo, $users, $contacts); if ($possibleInvitee == true) { $userInfo['notify_user']->new_assigned_user_name = "{$userInfo['notify_user']->first_name} {$userInfo['notify_user']->last_name}"; $error = false; // true=encountered an error; false=no errors if ($type == "Default") { $error = get_system_default_body($mailer, $focus, $userInfo['notify_user']); } else { $error = create_email_body($focus, $mailer, $admin, $alert_msg, $alert_shell_array, $userInfo['notify_user']->id); } if ($error) { throw new MailerException("Failed to add message content", MailerException::InvalidMessageBody); } $mailer->send(); } } catch (MailerException $me) { $message = $me->getMessage(); $GLOBALS["log"]->warn("Notifications: error sending e-mail (method: {$mailTransmissionProtocol}), (error: {$message})"); } } } catch (MailerException $me) { $message = $me->getMessage(); $GLOBALS["log"]->warn("Notifications: error sending e-mail (method: {$mailTransmissionProtocol}), (error: {$message})"); } if ($invite_person == true) { //Handle inviting users/contacts to meetings/calls if (!empty($address_array['invite_only'])) { foreach ($address_array['invite_only'] as $userInfo) { populate_usr_con_arrays($userInfo, $users, $contacts); } } //use the user_arr & contact_arr to add these people to the meeting $focus->users_arr = $users; $focus->contacts_arr = $contacts; invite_people($focus); } }