本文整理汇总了PHP中Swift_RecipientList::addCc方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_RecipientList::addCc方法的具体用法?PHP Swift_RecipientList::addCc怎么用?PHP Swift_RecipientList::addCc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_RecipientList
的用法示例。
在下文中一共展示了Swift_RecipientList::addCc方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDuplicateEntriesInSameFieldAreOverWritten
/**
* Test that only no duplicates can exist.
*/
public function testDuplicateEntriesInSameFieldAreOverWritten()
{
$list = new Swift_RecipientList();
$list->addCc(new Swift_Address("foo@bar.com"));
$list->addCc("joe@bloggs.com", "Joe");
$list->addCc("jim@somewhere.co.uk");
$list->addCc("foo@bar.com", "Foo");
$this->assertEqual(3, count($list->getCc()));
}
示例2: _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;
}
}
示例3: sendEmail
private function sendEmail($notificationIds, $swift, $userId, $emailContent, $cc)
{
// Use a transaction to allow us to prevent the email sending and marking of notification as done
// getting out of step
$this->db->begin();
try {
$this->db->set('acknowledged', 't')->from('notifications')->in('id', $notificationIds)->update();
$email_config = Kohana::config('email');
$userResults = $this->db->select('people.email_address')->from('people')->join('users', 'users.person_id', 'people.id')->where('users.id', $userId)->limit(1)->get();
if (!isset($email_config['address'])) {
self::msg('Email address not provided in email configuration', 'error');
return;
}
foreach ($userResults as $user) {
$message = new Swift_Message(kohana::lang('misc.notification_subject', kohana::config('email.server_name')), $emailContent, 'text/html');
$recipients = new Swift_RecipientList();
$recipients->addTo($user->email_address);
$cc = explode(',', $cc);
foreach ($cc as $ccEmail) {
$recipients->addCc(trim($ccEmail));
}
// send the email
$swift->send($message, $recipients, $email_config['address']);
kohana::log('info', 'Email notification sent to ' . $user->email_address);
}
} catch (Exception $e) {
// Email not sent, so undo marking of notification as complete.
$this->db->rollback();
throw $e;
}
$this->db->commit();
}
示例4: gmail
function gmail(&$error, $to, $subject, $body, $fromName = "", $html = 0, $repto = "", $from = "", $cc = "", $reptoName = "")
{
global $errorReportingLevel;
require_once GORUM_DIR . "/SwiftMailer/Swift.php";
$_S =& new AppSettings();
error_reporting(0);
$log =& Swift_LogContainer::getLog();
$log->setLogLevel($_S->swiftLog);
Swift_Errors::expect($e, "Swift_Exception");
if ($_S->smtpServer) {
require_once GORUM_DIR . "/SwiftMailer/Swift/Connection/SMTP.php";
if ($_S->fallBackNative) {
require_once GORUM_DIR . "/SwiftMailer/Swift/Connection/NativeMail.php";
require_once GORUM_DIR . "/SwiftMailer/Swift/Connection/Multi.php";
$connections = array();
$conn =& new Swift_Connection_SMTP($_S->smtpServer);
$conn->setUsername($_S->smtpUser);
$conn->setPassword($_S->smtpPass);
$conn->setPort($_S->smtpPort);
$conn->setPort($_S->smtpPort);
$conn->setEncryption($_S->smtpSecure);
if ($e !== null) {
$error = $e->getMessage();
return;
}
$connections[] =& $conn;
// Fall back to native mail:
$connections[] =& new Swift_Connection_NativeMail();
if ($e !== null) {
$error = $e->getMessage();
return;
}
$swift =& new Swift(new Swift_Connection_Multi($connections));
} else {
$connection =& new Swift_Connection_SMTP($_S->smtpServer);
$connection->setUsername($_S->smtpUser);
$connection->setPassword($_S->smtpPass);
$connection->setPort($_S->smtpPort);
$connection->setEncryption($_S->smtpSecure);
if ($e !== null) {
$error = $e->getMessage();
return;
}
$swift =& new Swift($connection);
}
} else {
require_once GORUM_DIR . "/SwiftMailer/Swift/Connection/NativeMail.php";
$swift =& new Swift(new Swift_Connection_NativeMail());
}
error_reporting($errorReportingLevel);
if ($e !== null) {
$error = $e->getMessage();
return;
} else {
$error = "";
Swift_Errors::clear("Swift_Exception");
}
$subject = str_replace(array("<", ">"), array("<", ">"), $subject);
$charset = "utf-8";
$message =& new Swift_Message($subject);
$message->setCharset($charset);
$part1 =& new Swift_Message_Part($body, "text/html");
$part1->setCharset($charset);
$message->attach($part1);
$part2 =& new Swift_Message_Part(strip_tags($body));
$part2->setCharset($charset);
$message->attach($part2);
if ($repto) {
$message->setReplyTo(new Swift_Address($repto, $reptoName));
}
error_reporting(0);
Swift_Errors::expect($e, "Swift_Exception");
$recipients = new Swift_RecipientList();
$recipients->addTo($to);
if ($this->cc) {
$recipients->addCc($this->cc);
}
$swift->send($message, $recipients, new Swift_Address($from, $fromName));
if ($e !== null) {
$error = $e->getMessage();
} else {
$error = "";
Swift_Errors::clear("Swift_Exception");
}
$swift->disconnect();
error_reporting($errorReportingLevel);
}
示例5: sendTicketMessage
//.........这里部分代码省略.........
$mail->setTo($first_address->email);
// Not an auto-reply
} else {
// Forwards
if (!empty($properties['to'])) {
$to = array();
$aTo = DevblocksPlatform::parseCsvString(str_replace(';', ',', $properties['to']));
foreach ($aTo as $addy) {
$to[] = new Swift_Address($addy);
$sendTo->addTo($addy);
}
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;
}
示例6: testFailedRecipientsAreReturned
public function testFailedRecipientsAreReturned()
{
$conn = new FullMockConnection();
$conn->setReturnValueAt(0, "read", "220 xxx ESMTP");
$conn->setReturnValueAt(1, "read", "250-Hello xxx\r\n250 HELP");
$conn->setReturnValueAt(2, "read", "250 Ok");
$conn->setReturnValueAt(3, "read", "550 Denied");
$conn->setReturnValueAt(4, "read", "250 ok");
$conn->setReturnValueAt(5, "read", "550 Denied");
$conn->setReturnValueAt(6, "read", "354 Go ahead");
$conn->setReturnValueAt(7, "read", "250 ok");
$log = Swift_LogContainer::getLog();
$swift = new Swift($conn, "abc", Swift::ENABLE_LOGGING);
$message = new Swift_Message("My Subject", "my body");
$recipients = new Swift_RecipientList();
$recipients->addTo("xxx@yyy.tld", "XXX YYY");
$recipients->addTo("someone@somewhere.tld");
$recipients->addCc("abc@def.tld");
$this->assertEqual(1, $swift->send($message, $recipients, new Swift_Address("foo@bar.tld", "Foo Bar")));
$this->assertEqual(array("xxx@yyy.tld", "abc@def.tld"), $log->getFailedRecipients());
}