本文整理汇总了PHP中Swift_RecipientList::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_RecipientList::add方法的具体用法?PHP Swift_RecipientList::add怎么用?PHP Swift_RecipientList::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_RecipientList
的用法示例。
在下文中一共展示了Swift_RecipientList::add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSwiftAddresses
/**
* Returns an instance of Swift_RecipientList, based on an address or an array of addresses.
*
* @see getSwiftAddress()
*
* @param $addresses
* @return array of Swift_Address | Swift_RecipientList
*/
protected static function getSwiftAddresses($addresses, $recipient_list = false, $type = 'to')
{
// Detect single address
$address = self::getSwiftAddress($addresses);
// Single address detected
if ($address instanceof Swift_Address) {
$result = array($address);
} else {
$result = array();
foreach ($addresses as $address) {
$result[] = self::getSwiftAddress($address);
}
}
// transform into a recipient list if asked to
if ($recipient_list) {
$addresses = $result;
$result = new Swift_RecipientList();
$result->add($addresses, null, $type);
}
return $result;
}
示例2: array
/**
* Mass mailer
*
* @param void
* @return null
*/
function mass_mailer()
{
if (!MASS_MAILER_ENABLED) {
$this->httpError(HTTP_ERR_FORBIDDEN);
}
// if
$email_data = $this->request->post('email');
$this->smarty->assign(array('email_data' => $email_data, 'exclude' => array($this->logged_user->getId())));
if ($this->request->isSubmitted()) {
$errors = new ValidationErrors();
$subject = trim(array_var($email_data, 'subject'));
$body = trim(array_var($email_data, 'body'));
$recipient_ids = array_var($email_data, 'recipients');
if (empty($subject)) {
$errors->addError(lang('Subject is required'), 'subject');
}
// if
if (empty($body)) {
$errors->addError(lang('Body is required'), 'body');
}
// if
$recipients = array();
if (is_foreachable($recipient_ids)) {
$recipients = Users::findByIds(array_unique($recipient_ids));
}
// if
if (!is_foreachable($recipients)) {
$errors->addError(lang('Please select recipients'), 'recipients');
}
// if
if ($errors->hasErrors()) {
$this->smarty->assign('errors', $errors);
$this->render();
}
// if
$mailer =& ApplicationMailer::mailer();
$message = new Swift_Message($subject, $body, 'text/html', EMAIL_ENCODING, EMAIL_CHARSET);
$recipients_list = new Swift_RecipientList();
foreach ($recipients as $recipient) {
$name = $recipient->getDisplayName();
$email = $recipient->getEmail();
if ($name == $email) {
$name = '';
}
// if
$recipients_list->add($email, $name);
}
// foreach
$name = $this->logged_user->getDisplayName();
$email = $this->logged_user->getEmail();
if ($name == $email) {
$name = '';
}
// if
if ($mailer->batchSend($message, $recipients_list, new Swift_Address($email, $name))) {
flash_success('Email has been successfully sent');
} else {
flash_error('Failed to send email');
}
// if
$this->redirectTo('admin_tools_mass_mailer');
}
// if
}