public function send($members, array $vars = array()) { if (!is_array($members)) { $members = array($members); } foreach ($members as $member_id) { $email = new LibraryEmail(); $member = self::$_Members->fetchMemberFromID($member_id); $email->to = $member->getData(extension_Members::memberEmailFieldID(), true)->value; $email->from = sprintf('%s <%s>', Symphony::Configuration()->get('sitename', 'general'), 'noreply@' . parse_url(URL, PHP_URL_HOST)); $email->subject = $this->__replaceFieldsInString($this->__replaceVarsInString($this->subject, $vars), $member); $email->body = $this->__replaceFieldsInString($this->__replaceVarsInString($this->body, $vars), $member); try { return $email->send(); } catch (Exception $e) { // It's okay to discard errors } unset($email); } }
public function cbSendEmailSMTPFilter(array $context = array()) { if (!@in_array('smtp-email-library-send-email-filter', $context['event']->eParamFILTERS)) { return; } $fields = $_POST['send-email']; $fields['recipient'] = $this->__sendEmailFindFormValue($fields['recipient'], $_POST['fields'], true); $fields['recipient'] = preg_split('/\\,/i', $fields['recipient'], -1, PREG_SPLIT_NO_EMPTY); $fields['recipient'] = array_map('trim', $fields['recipient']); $fields['recipient'] = Symphony::Database()->fetch("SELECT `email`, CONCAT(`first_name`, ' ', `last_name`) AS `name` FROM `tbl_authors` WHERE `username` IN ('" . @implode("', '", $fields['recipient']) . "') "); $fields['subject'] = $this->__sendEmailFindFormValue($fields['subject'], $context['fields'], true, __('[Symphony] A new entry was created on %s', array(Symphony::Configuration()->get('sitename', 'general')))); $fields['body'] = $this->__sendEmailFindFormValue($fields['body'], $context['fields'], false, NULL, false); $fields['sender-email'] = $this->__sendEmailFindFormValue($fields['sender-email'], $context['fields'], true, 'noreply@' . parse_url(URL, PHP_URL_HOST)); $fields['sender-name'] = $this->__sendEmailFindFormValue($fields['sender-name'], $context['fields'], true, 'Symphony'); $fields['from'] = $this->__sendEmailFindFormValue($fields['from'], $context['fields'], true, $fields['sender-email']); $section = Symphony::Database()->fetchRow(0, "SELECT * FROM `tbl_sections` WHERE `id` = " . $context['event']->getSource() . " LIMIT 1"); $edit_link = URL . '/symphony/publish/' . $section['handle'] . '/edit/' . $context['entry_id'] . '/'; $body = __('Dear <!-- RECIPIENT NAME -->,') . General::CRLF . General::CRLF . __('This is a courtesy email to notify you that an entry was created on the %1$s section. You can edit the entry by going to: %2$s', array($section['name'], $edit_link)) . General::CRLF . General::CRLF; if (is_array($fields['body'])) { foreach ($fields['body'] as $field_handle => $value) { $body .= "=== {$field_handle} ===" . General::CRLF . General::CRLF . $value . General::CRLF . General::CRLF; } } else { $body .= $fields['body']; } $errors = array(); if (!is_array($fields['recipient']) || empty($fields['recipient'])) { $context['messages'][] = array('smtp-email-library-send-email-filter', false, __('No valid recipients found. Check send-email[recipient] field.')); } else { foreach ($fields['recipient'] as $r) { $email = new LibraryEmail(); $email->to = vsprintf('%2$s <%1$s>', array_values($r)); $email->from = sprintf('%s <%s>', $fields['sender-name'], $fields['sender-email']); $email->subject = $fields['subject']; $email->message = str_replace('<!-- RECIPIENT NAME -->', $r['name'], $body); $email->setHeader('Reply-To', $fields['from']); try { $email->send(); } catch (Exception $e) { $errors[] = $email; } } if (!empty($errors)) { $context['messages'][] = array('smtp-email-library-send-email-filter', false, 'The following email addresses were problematic: ' . General::sanitize(implode(', ', $errors))); } else { $context['messages'][] = array('smtp-email-library-send-email-filter', true); } } }