本文整理汇总了PHP中Swift_RecipientList::addBcc方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_RecipientList::addBcc方法的具体用法?PHP Swift_RecipientList::addBcc怎么用?PHP Swift_RecipientList::addBcc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_RecipientList
的用法示例。
在下文中一共展示了Swift_RecipientList::addBcc方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddressesCanBeRemoved
/**
* Test that addresses can be taken back out of the list once added.
*/
public function testAddressesCanBeRemoved()
{
$list = new Swift_RecipientList();
$list->addBcc(new Swift_Address("foo@bar.com"));
$list->addBcc("joe@bloggs.com", "Joe");
$list->addBcc("jim@somewhere.co.uk");
$list->removeBcc("joe@bloggs.com");
$this->assertEqual(array("foo@bar.com", "jim@somewhere.co.uk"), array_keys($list->getBcc()));
}
示例2: send
/**
* Send a contact mail (text only) with the data provided by the given form.
*
* @uses Swift
*
* @throws InvalidArgumentException
* @throws RuntimeException
*
* @param sfContactForm $form A valid contact form which contains the content.
* @param sfContactFormDecorator $decorator Defaults to null. If given, the decorated subject and message will be used.
*
* @return bool True if all recipients got the mail.
*/
public static function send(sfContactForm $form, sfContactFormDecorator $decorator = null)
{
if (!$form->isValid()) {
throw new InvalidArgumentException('The given form is not valid.', 1);
}
if (!class_exists('Swift')) {
throw new RuntimeException('Swift could not be found.');
}
// set up sender
$from = sfConfig::get('sf_contactformplugin_from', false);
if ($from === false) {
throw new InvalidArgumentException('Configuration value of sf_contactformplugin_from is missing.', 2);
}
// where to send the contents of the contact form
$mail = sfConfig::get('sf_contactformplugin_mail', false);
if ($mail === false) {
throw new InvalidArgumentException('Configuration value of sf_contactformplugin_mail is missing.', 3);
}
// set up mail content
if (!is_null($decorator)) {
$subject = $decorator->getSubject();
$body = $decorator->getMessage();
} else {
$subject = $form->getValue('subject');
$body = $form->getValue('message');
}
// set up recipients
$recipients = new Swift_RecipientList();
// check amount for given recipients
$recipientCheck = 0;
// use the sender as recipient to apply other recipients only as blind carbon copy
$recipients->addTo($from);
$recipientCheck++;
// add a mail where to send the message
$recipients->addBcc($mail);
$recipientCheck++;
// add sender to recipients, if chosen
if ($form->getValue('sendcopy')) {
$recipients->addBcc($form->getValue('email'));
$recipientCheck++;
}
if (count($recipients->getIterator('bcc')) === 0) {
throw new InvalidArgumentException('There are no recipients given.', 4);
}
// send the mail using swift
try {
$mailer = new Swift(new Swift_Connection_NativeMail());
$message = new Swift_Message($subject, $body, 'text/plain');
$countRecipients = $mailer->send($message, $recipients, $from);
$mailer->disconnect();
return $countRecipients == $recipientCheck;
} catch (Exception $e) {
$mailer->disconnect();
throw $e;
}
}
示例3: executeRegister
public function executeRegister($request)
{
$userParams = $request->getParameter('api_user');
$this->user_form = new ApiUserForm();
$this->created = false;
if ($request->isMethod('post')) {
//bind request params to form
$captcha = array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field'));
$userParams = array_merge($userParams, array('captcha' => $captcha));
$this->user_form->bind($userParams);
//look for user with duplicate email
$q = LsDoctrineQuery::create()->from('ApiUser u')->where('u.email = ?', $userParams['email']);
if ($q->count()) {
$validator = new sfValidatorString(array(), array('invalid' => 'There is already an API user with that email address.'));
$this->user_form->getErrorSchema()->addError(new sfValidatorError($validator, 'invalid'), 'email');
$request->setError('email', 'There is already a user with that email');
}
if ($this->user_form->isValid() && !$request->hasErrors()) {
//create inactive api user
$user = new ApiUser();
$user->name_first = $userParams['name_first'];
$user->name_last = $userParams['name_last'];
$user->email = $userParams['email'];
$user->reason = $userParams['reason'];
$user->api_key = $user->generateKey();
$user->is_active = 1;
$user->save();
//add admin notification email to queue
$email = new ScheduledEmail();
$email->from_name = sfConfig::get('app_mail_sender_name');
$email->from_email = sfConfig::get('app_mail_sender_address');
$email->to_name = sfConfig::get('app_mail_sender_name');
$email->to_email = sfConfig::get('app_mail_sender_address');
$email->subject = sprintf("%s (%s) has requested an API key", $user->getFullName(), $user->email);
$email->body_text = $this->getPartial('keyrequestnotify', array('user' => $user));
$email->save();
$this->created = true;
//send approval email
$mailBody = $this->getPartial('keycreatenotify', array('user' => $user));
$mailer = new Swift(new Swift_Connection_NativeMail());
$message = new Swift_Message('Your LittleSis API key', $mailBody, 'text/plain');
$from = new Swift_Address(sfConfig::get('app_mail_sender_address'), sfConfig::get('app_mail_sender_name'));
$recipients = new Swift_RecipientList();
$recipients->addTo($user->email, $user->name_first . ' ' . $user->name_last);
$recipients->addBcc(sfConfig::get('app_mail_sender_address'));
$mailer->send($message, $recipients, $from);
$mailer->disconnect();
}
}
}
示例4: executeApproveUser
public function executeApproveUser($request)
{
if ($request->isMethod('post')) {
if (!($apiUser = Doctrine::getTable('ApiUser')->find($request->getParameter('id')))) {
$this->forward404();
}
$apiUser->is_active = 1;
$apiUser->save();
//send approval email
$mailBody = $this->getPartial('accountcreatenotify', array('user' => $apiUser));
$mailer = new Swift(new Swift_Connection_NativeMail());
$message = new Swift_Message('Your LittleSis API key', $mailBody, 'text/plain');
$from = new Swift_Address(sfConfig::get('app_api_sender_address'), sfConfig::get('app_api_sender_name'));
$recipients = new Swift_RecipientList();
$recipients->addTo($apiUser['email'], $apiUser['name_first'] . ' ' . $apiUser['name_last']);
$recipients->addBcc(sfConfig::get('app_api_sender_address'));
$mailer->send($message, $recipients, $from);
$mailer->disconnect();
}
$this->redirect('api/users');
}
示例5: Send
//.........这里部分代码省略.........
}
if (is_array($to_name)) {
if ($to_name && is_array($to_name) && Validate::isGenericName($to_name[$key])) {
$to_name = $to_name[$key];
}
}
if ($to_name == null || $to_name == $addr) {
$to_name = '';
} else {
if (function_exists('mb_encode_mimeheader')) {
$to_name = mb_encode_mimeheader($to_name, 'utf-8');
} else {
$to_name = self::mimeEncode($to_name);
}
}
$to_list->addTo($addr, $to_name);
}
$to_plugin = $to[0];
} else {
/* Simple recipient, one address */
$to_plugin = $to;
if ($to_name == null || $to_name == $to) {
$to_name = '';
} else {
if (function_exists('mb_encode_mimeheader')) {
$to_name = mb_encode_mimeheader($to_name, 'utf-8');
} else {
$to_name = self::mimeEncode($to_name);
}
}
$to_list->addTo($to, $to_name);
}
if (isset($bcc)) {
$to_list->addBcc($bcc);
}
$to = $to_list;
try {
/* Connect with the appropriate configuration */
if ($configuration['PS_MAIL_METHOD'] == 2) {
if (empty($configuration['PS_MAIL_SERVER']) || empty($configuration['PS_MAIL_SMTP_PORT'])) {
Tools::dieOrLog(Tools::displayError('Error: invalid SMTP server or SMTP port'), $die);
return false;
}
$connection = new Swift_Connection_SMTP($configuration['PS_MAIL_SERVER'], $configuration['PS_MAIL_SMTP_PORT'], $configuration['PS_MAIL_SMTP_ENCRYPTION'] == 'ssl' ? Swift_Connection_SMTP::ENC_SSL : ($configuration['PS_MAIL_SMTP_ENCRYPTION'] == 'tls' ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF));
$connection->setTimeout(4);
if (!$connection) {
return false;
}
if (!empty($configuration['PS_MAIL_USER'])) {
$connection->setUsername($configuration['PS_MAIL_USER']);
}
if (!empty($configuration['PS_MAIL_PASSWD'])) {
$connection->setPassword($configuration['PS_MAIL_PASSWD']);
}
} else {
$connection = new Swift_Connection_NativeMail();
}
if (!$connection) {
return false;
}
$swift = new Swift($connection, Configuration::get('PS_MAIL_DOMAIN', null, null, $id_shop));
/* Get templates content */
$iso = Language::getIsoById((int) $id_lang);
if (!$iso) {
Tools::dieOrLog(Tools::displayError('Error - No ISO code for email'), $die);
return false;
示例6: _send
//.........这里部分代码省略.........
* embed-images is an associative array of key => image light path.
* You can use "%%IMG_name-of-image%%" in the body or in any part to reference the corresponding embedded image.
*
* @param array $options
* @throws Exception
* @return int The number of successful recipients
*/
protected static function _send(array $options)
{
$options = array_merge(sfConfig::get('app_mailer_defaults', array()), $options);
// Mailer
if (!isset($options['connection'])) {
throw new Exception('Connection configuration required');
}
if (!isset($options['connection']['type'])) {
throw new Exception('Connection type undefined');
}
if (!isset($options['connection']['params'])) {
$options['connection']['params'] = array();
}
$connection = self::getConnection($options['connection']['type'], $options['connection']['params']);
$mailer = new Swift($connection);
$to = new Swift_RecipientList();
$to->addTo(self::getSwiftAddresses($options['to']));
// Basic elements
$from = self::getSwiftAddress($options['from']);
if (!isset($options['subject'])) {
throw new Exception('Subject required');
}
if (!isset($options['subject-template'])) {
$options['subject-template'] = '%s';
}
if (!isset($options['i18n-catalogue'])) {
$options['i18n-catalogue'] = 'messages';
}
$subject = self::getI18NString($options['subject'], $options['subject-template'], $options['i18n-catalogue']);
// Message to be sent
$mail = new Swift_Message($subject);
// Embedded images
if (isset($options['embed-images'])) {
$embedded_images = self::embedImages($mail, @$options['embed-images']);
} else {
$embedded_images = array();
}
// Get body as the main part
if (!isset($options['body'])) {
throw new Exception('Body is required');
}
if (!is_array($options['body'])) {
$options['body'] = array('content' => $options['body']);
}
$body = self::getPart($options['body'], $embedded_images);
// Attach files
if (isset($options['attachments']) && is_array($options['attachments'])) {
// Known bug : When we have attachments, we must have body declared as a part, or the
// mail will be received with no body. We fix this here :
if (!isset($options['parts'])) {
$options['parts'] = array();
}
foreach ($options['attachments'] as $attachment) {
$mail->attach(self::getAttachment($attachment));
}
}
// Attach parts (body is the first one)
if (isset($options['parts']) && is_array($options['parts'])) {
$parts = self::getParts($options['parts'], $embedded_images);
array_unshift($parts, $body);
foreach ($parts as $part) {
$mail->attach($part);
}
} else {
$mail->setBody($body->getData());
$mail->setCharset($body->getCharset());
$mail->setEncoding($body->getEncoding());
$mail->setContentType($body->getContentType());
}
// Handle other options
if (isset($options['bcc'])) {
$to->addBcc(self::getSwiftAddresses($options['bcc']));
}
if (isset($options['cc'])) {
$to->addCc(self::getSwiftAddresses($options['cc']));
}
if (isset($options['reply-to'])) {
$mail->setReplyTo(self::getSwiftAddresses($options['reply-to']));
}
if (isset($options['return-path'])) {
$mail->setReturnPath(self::getSwiftAddress($options['return-path']));
}
try {
// Try to send the mail
$result = $mailer->send($mail, $to, $from);
$mailer->disconnect();
return $result;
} catch (Exception $e) {
// An error occured, disconnect an eventual connection, and forwards the exception
$mailer->disconnect();
throw $e;
}
}
示例7: sendTicketMessage
//.........这里部分代码省略.........
if (!empty($to)) {
$mail->setTo($to);
}
// Replies
} else {
// Recipients
$to = array();
$requesters = DAO_Ticket::getRequestersByTicket($ticket_id);
if (is_array($requesters)) {
foreach ($requesters as $requester) {
/* @var $requester Model_Address */
$to[] = new Swift_Address($requester->email);
$sendTo->addTo($requester->email);
}
}
$mail->setTo($to);
}
// Ccs
if (!empty($properties['cc'])) {
$ccs = array();
$aCc = DevblocksPlatform::parseCsvString(str_replace(';', ',', $properties['cc']));
foreach ($aCc as $addy) {
$sendTo->addCc($addy);
$ccs[] = new Swift_Address($addy);
}
if (!empty($ccs)) {
$mail->setCc($ccs);
}
}
// Bccs
if (!empty($properties['bcc'])) {
$aBcc = DevblocksPlatform::parseCsvString(str_replace(';', ',', $properties['bcc']));
foreach ($aBcc as $addy) {
$sendTo->addBcc($addy);
}
}
}
/*
* [IMPORTANT -- Yes, this is simply a line in the sand.]
* You're welcome to modify the code to meet your needs, but please respect
* our licensing. Buy a legitimate copy to help support the project!
* http://www.cerberusweb.com/
*/
$license = CerberusLicense::getInstance();
if (empty($license) || @empty($license['serial'])) {
$content .= base64_decode("DQoNCi0tLQ0KQ29tYmF0IHNwYW0gYW5kIGltcHJvdmUgcmVzc" . "G9uc2UgdGltZXMgd2l0aCBDZXJiZXJ1cyBIZWxwZGVzayA0LjAhDQpodHRwOi8vd3d3LmNlc" . "mJlcnVzd2ViLmNvbS8NCg");
}
// Body
$mail->attach(new Swift_Message_Part($content, 'text/plain', 'base64', LANG_CHARSET_CODE));
// Mime Attachments
if (is_array($files) && !empty($files)) {
foreach ($files['tmp_name'] as $idx => $file) {
if (empty($file) || empty($files['name'][$idx])) {
continue;
}
$mail->attach(new Swift_Message_Attachment(new Swift_File($file), $files['name'][$idx], $files['type'][$idx]));
}
}
// Forward Attachments
if (!empty($forward_files) && is_array($forward_files)) {
$attachments_path = APP_STORAGE_PATH . '/attachments/';
foreach ($forward_files as $file_id) {
$attachment = DAO_Attachment::get($file_id);
$attachment_path = $attachments_path . $attachment->filepath;
$mail->attach(new Swift_Message_Attachment(new Swift_File($attachment_path), $attachment->display_name, $attachment->mime_type));
}