• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Swift_RecipientList类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Swift_RecipientList的典型用法代码示例。如果您正苦于以下问题:PHP Swift_RecipientList类的具体用法?PHP Swift_RecipientList怎么用?PHP Swift_RecipientList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Swift_RecipientList类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: testArraysCanBeAdded

 public function testArraysCanBeAdded()
 {
     $list = new Swift_RecipientList();
     $list->addTo("a@a");
     $list->addTo(array("b@b", "a@a", "c@c"));
     $list->addTo(array(new Swift_Address("d@d", "D"), "e@e"), "E");
     $this->assertEqual(array("a@a", "b@b", "c@c", "d@d", "e@e"), array_keys($list->getTo()));
 }
开发者ID:Esleelkartea,项目名称:legedia-ESLE,代码行数:8,代码来源:TestOfRecipientList.php


示例2: getMessage

 public function getMessage(array $to, $from_email, $from_name, $subject, $message_body, array $attachments, $mail_type = 'html')
 {
     $to_list = new \Swift_RecipientList();
     foreach ($to as $key => $addr) {
         $to_list->addTo($addr);
     }
     $this->to_list = $to_list;
     $this->from_email = $from_email;
     $this->from_name = $from_name;
     $message = new \Swift_Message($subject, $message_body, "text/" . $mail_type);
     return $message;
 }
开发者ID:jaeger-app,项目名称:email,代码行数:12,代码来源:Swift3.php


示例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();
         }
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:50,代码来源:actions.class.php


示例4: send_email

 private function send_email($email, $subject, $content)
 {
     $swift = email::connect();
     $from = '[email protected]';
     $subject = $subject;
     $message = $content;
     if (!IN_PRODUCTION) {
         echo $content;
     }
     $recipients = new Swift_RecipientList();
     $recipients->addTo($email);
     // Build the HTML message
     $message = new Swift_Message($subject, $message, "text/html");
     $succeeded = !!$swift->send($message, $recipients, $from);
     $swift->disconnect();
     return $succeeded;
 }
开发者ID:jverkoey,项目名称:uwdata.ca,代码行数:17,代码来源:signup.php


示例5: send_email

 private function send_email($result)
 {
     // Create new password for customer
     $new_pass = text::random('numeric', 8);
     if (isset($result->member_email) && !empty($result->member_email)) {
         $result->member_pw = md5($new_pass);
     }
     $result->save();
     //Use connect() method to load Swiftmailer
     $swift = email::connect();
     //From, subject
     //$from = array($this->site['site_email'], 'Yesnotebook get password');
     $from = $this->site['site_email'];
     $subject = 'Your Temporary Password for ' . $this->site['site_name'];
     //HTML message
     //print_r($html_content);die();
     //Replate content
     $html_content = $this->Data_template_Model->get_value('EMAIL_FORGOTPASS');
     $name = $result->member_fname . ' ' . $result->member_lname;
     $html_content = str_replace('#name#', $name, $html_content);
     if (isset($result->member_email) && !empty($result->member_email)) {
         $html_content = str_replace('#username#', $result->member_email, $html_content);
     }
     $html_content = str_replace('#site#', substr(url::base(), 0, -1), $html_content);
     $html_content = str_replace('#sitename#', $this->site['site_name'], $html_content);
     $html_content = str_replace('#password#', $new_pass, $html_content);
     $html_content = str_replace('#EmailAddress#', $this->site['site_email'], $html_content);
     //fwrite($fi, $html_content);
     //Build recipient lists
     $recipients = new Swift_RecipientList();
     if (isset($result->member_email) && !empty($result->member_email)) {
         $recipients->addTo($result->member_email);
     }
     //Build the HTML message
     $message = new Swift_Message($subject, $html_content, "text/html");
     if ($swift->send($message, $recipients, $from)) {
         //$this->session->set_flash('success_msg',Kohana::lang('errormsg_lang.info_mail_change_pass'));
         if (isset($result->member_email) && !empty($result->member_email)) {
             url::redirect(url::base() . 'forgotpass/thanks/' . $result->uid . '/customer');
         }
         die;
     } else {
     }
     // Disconnect
     $swift->disconnect();
 }
开发者ID:vobinh,项目名称:PHP,代码行数:46,代码来源:forgotpass.php


示例6: 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');
 }
开发者ID:silky,项目名称:littlesis,代码行数:21,代码来源:actions.class.php


示例7: enviarEmailDefault

 /**
  * Envía un email a través de la configuración de campanias de la empresa que se pasa como parámetro. Utiliza el plugin sfSwiftPlugin
  * @param id_empresa, identificador de la empresa a través de la que se envia el mensaje.
  * @param asunto, asunto del mensaje
  * @param cuerpo, cuerpo del mensaje
  * @param lista_emails, lista de emails, a los que se envia el mensjae.
  * @return integer, número de mensajes enviados
  * @version 25-02-09
  * @author Ana Martin
  */
 public static function enviarEmailDefault($id_empresa, $asunto, $cuerpo, $lista_emails)
 {
     $empresa = EmpresaPeer::retrievebypk($id_empresa);
     if ($empresa instanceof Empresa) {
         $smtp_server = $empresa->getSmtpServer();
         $smtp_user = $empresa->getSmtpUser();
         $smtp_password = $empresa->getSmtpPassword();
         $smtp_port = $empresa->getSmtpPort();
         $sender_email = $empresa->getSenderAddress();
         $sender_name = $empresa->getSenderName();
         //$c = new Criteria();
         //$c->add(PlantillaPeer::ID_EMPRESA, $empresa->getIdEmpresa());
         //$plantilla = PlantillaPeer::doSelectOne($c);
         $plantilla = "";
         $cuerpo = MensajePeer::prepararMailingCuerpoDefault($cuerpo, $plantilla, $asunto);
         $smtp = new Swift_Connection_SMTP($smtp_server, $smtp_port);
         $smtp->setUsername($smtp_user);
         $smtp->setpassword($smtp_password);
         $mailer = new Swift($smtp);
         $message = new Swift_Message(utf8_decode($asunto));
         $message->attach(new Swift_Message_Part($cuerpo, "text/html"));
         $recipients = new Swift_RecipientList();
         foreach ($lista_emails as $email) {
             $recipients->addTo($email);
         }
         //Load the plugin with these replacements
         /*  $replacaments = array(
                        '{FECHA}' => date('d-m-Y') , 
                        '{ASUNTO}' => utf8_decode($asunto),
                        '{MENSAJE}' => utf8_decode($cuerpo),             
                     );
          	  $mailer->attachPlugin(new Swift_Plugin_Decorator($replacaments), "decorator");*/
         $enviado_por = new Swift_Address($sender_email, $sender_name);
         $cuantos = $mailer->send($message, $recipients, $enviado_por);
         $mailer->disconnect();
         return $cuantos;
     } else {
         return 0;
     }
 }
开发者ID:Esleelkartea,项目名称:legedia-ESLE,代码行数:50,代码来源:MensajePeer.php


示例8: 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;
     }
 }
开发者ID:havvg,项目名称:sfContactFormPlugin,代码行数:69,代码来源:sfContactFormMail.class.php


示例9: send_email

 private function send_email($result)
 {
     //Use connect() method to load Swiftmailer
     $swift = email::connect();
     //From, subject
     //$from = array($this->site['site_email'], 'Yesnotebook get password');
     $str_random = rand(1000, 9999);
     $from = $this->site['site_email'];
     $subject = 'Forgot your password ' . $this->site['site_name'];
     //HTML message
     $path = 'application/views/email_tpl/forgotpass.tpl';
     $fi = fopen($path, 'r+');
     $html_content = file_get_contents($path);
     //Replate content
     $name = $result->admin_name;
     $html_content = str_replace('#first_name#', $name, $html_content);
     $html_content = str_replace('#username#', $result->admin_name, $html_content);
     $html_content = str_replace('#sitename#', $this->site['site_name'], $html_content);
     $html_content = str_replace('#password#', $str_random, $html_content);
     //fwrite($fi, $html_content);
     fclose($fi);
     //Build recipient lists
     $recipients = new Swift_RecipientList();
     $recipients->addTo($result->admin_email);
     //Build the HTML message
     $message = new Swift_Message($subject, $html_content, "text/html");
     if ($swift->send($message, $recipients, $from)) {
         $this->session->set_flash('success_msg', Kohana::lang('errormsg_lang.msg_thanks_post'));
         $this->db->update('admin', array('admin_pass' => md5($str_random)), array('admin_email' => $result->admin_email));
         url::redirect('admin_login/forget_pass');
         die;
     } else {
     }
     // Disconnect
     $swift->disconnect();
 }
开发者ID:vobinh,项目名称:PHP,代码行数:36,代码来源:frm_bk.php


示例10: doRecordOwnerNotifications

 /**
  * Look for records posted by recorders who have given their email address and want to receive a summary of the record they are posting.
  */
 private function doRecordOwnerNotifications($swift)
 {
     // Get a list of the records which contributors want to get a summary back for
     $emailsRequired = $this->db->select('DISTINCT occurrences.id as occurrence_id, sav2.text_value as email_address, surveys.title as survey')->from('occurrences')->join('samples', 'samples.id', 'occurrences.sample_id')->join('surveys', 'surveys.id', 'samples.survey_id')->join('sample_attribute_values as sav1', 'sav1.sample_id', 'samples.id')->join('sample_attributes as sa1', 'sa1.id', 'sav1.sample_attribute_id')->join('sample_attribute_values as sav2', 'sav2.sample_id', 'samples.id')->join('sample_attributes as sa2', 'sa2.id', 'sav2.sample_attribute_id')->where(array('sa1.caption' => 'Email me a copy of the record', 'sa2.caption' => 'Email', 'samples.created_on>=' => $this->last_run_date))->get();
     // get a list of the records we need details of, so we can hit the db more efficiently.
     $recordsToFetch = array();
     foreach ($emailsRequired as $email) {
         $recordsToFetch[] = $email->occurrence_id;
     }
     $occurrences = $this->db->select('o.id, ttl.taxon, s.date_start, s.date_end, s.date_type, s.entered_sref as spatial_reference, ' . 's.location_name, o.comment as sample_comment, o.comment as occurrence_comment')->from('samples as s')->join('occurrences as o', 'o.sample_id', 's.id')->join('list_taxa_taxon_lists as ttl', 'ttl.id', 'o.taxa_taxon_list_id')->in('o.id', $recordsToFetch)->get();
     // Copy the occurrences to an array so we can build a structured list of data, keyed by ID
     $occurrenceArray = array();
     foreach ($occurrences as $occurrence) {
         $occurrenceArray[$occurrence->id] = $occurrence;
     }
     $attrArray = array();
     // Get the sample attributes
     $attrValues = $this->db->select('o.id, av.caption, av.value')->from('list_sample_attribute_values as av')->join('samples as s', 's.id', 'av.sample_id')->join('occurrences as o', 'o.sample_id', 's.id')->in('o.id', $recordsToFetch)->get();
     foreach ($attrValues as $attrValue) {
         $attrArray[$attrValue->id][$attrValue->caption] = $attrValue->value;
     }
     // Get the occurrence attributes
     $attrValues = $this->db->select('av.occurrence_id, av.caption, av.value')->from('list_occurrence_attribute_values av')->in('av.occurrence_id', $recordsToFetch)->get();
     foreach ($attrValues as $attrValue) {
         $attrArray[$attrValue->occurrence_id][$attrValue->caption] = $attrValue->value;
     }
     $email_config = Kohana::config('email');
     foreach ($emailsRequired as $email) {
         $emailContent = 'Thank you for sending your record to ' . $email->survey . '. Here are the details of your contribution for your records.<br/><table>';
         $this->addArrayToEmailTable($email->occurrence_id, $occurrenceArray, $emailContent);
         $this->addArrayToEmailTable($email->occurrence_id, $attrArray, $emailContent);
         $emailContent .= "</table>";
         $message = new Swift_Message(kohana::lang('misc.notification_subject', kohana::config('email.server_name')), $emailContent, 'text/html');
         $recipients = new Swift_RecipientList();
         $recipients->addTo($email->email_address);
         // send the email
         $swift->send($message, $recipients, $email_config['address']);
     }
 }
开发者ID:BirenRathod,项目名称:indicia-code,代码行数:42,代码来源:scheduled_tasks.php


示例11: sendEmailNotice

 /**
  * Used for sending errors/notices/warnings to a list of prescribed destinations
  * @param $subject
  * @param $msg
  * @return unknown_type
  */
 public static function sendEmailNotice($subject, $msg)
 {
     // register email notification parameters
     include sfContext::getInstance()->getConfigCache()->checkConfig('config/skuleGlobal.yml');
     $connection = new Swift_Connection_SMTP($mailNotificationParams['sender_smtp'], 465, $mailNotificationParams['sender_ssl'] ? Swift_Connection_SMTP::ENC_SSL : Swift_Connection_SMTP::ENC_OFF);
     $connection->setUsername($mailNotificationParams['sender_username']);
     $connection->setPassword($mailNotificationParams['sender_password']);
     $mailer = new Swift($connection);
     $message = new Swift_Message($subject, $msg);
     $recipients = new Swift_RecipientList();
     foreach ($mailNotificationParams['receiver'] as $address) {
         $recipients->addTo($address);
     }
     $mailer->send($message, $recipients, $mailNotificationParams['sender_address']);
     $mailer->disconnect();
 }
开发者ID:raymondlam,项目名称:SkuleCourses,代码行数:22,代码来源:functions.class.php


示例12: send_from_user

 public function send_from_user($id = null)
 {
     $email_config = Kohana::config('email');
     $this->template->title = 'Forgotten Password Email Request';
     $this->template->content = new View('login/login_message');
     $this->template->content->message = 'You are already logged in.<br />';
     $this->template->content->link_to_home = 'YES';
     $person = ORM::factory('person', $id);
     if (!$person->loaded) {
         $this->template->content->message = 'Invalid Person ID';
         return;
     }
     $user = ORM::factory('user', array('person_id' => $id));
     if (!$user->loaded) {
         $this->template->content->message = 'No user details have been set up for this Person';
         return;
     }
     if (!$this->check_can_login($user)) {
         return;
     }
     $link_code = $this->auth->hash_password($user->username);
     $user->__set('forgotten_password_key', $link_code);
     $user->save();
     try {
         $swift = email::connect();
         $message = new Swift_Message($email_config['forgotten_passwd_title'], View::factory('templates/forgotten_password_email_2')->set(array('server' => $email_config['server_name'], 'new_password_link' => '<a href="' . url::site() . 'new_password/email/' . $link_code . '">' . url::site() . 'new_password/email/' . $link_code . '</a>')), 'text/html');
         $recipients = new Swift_RecipientList();
         $recipients->addTo($person->email_address, $person->first_name . ' ' . $person->surname);
         $swift->send($message, $recipients, $email_config['address']);
     } catch (Swift_Exception $e) {
         kohana::log('error', "Error sending forgotten password: " . $e->getMessage());
         throw new Kohana_User_Exception('swift.general_error', $e->getMessage());
     }
     kohana::log('info', "Forgotten password sent to {$person->first_name} {$person->surname}");
     $this->session->set_flash('flash_info', "Forgotten password sent to {$person->first_name} {$person->surname}");
     url::redirect('user');
 }
开发者ID:BirenRathod,项目名称:indicia-code,代码行数:37,代码来源:forgotten_password.php


示例13: send

 /**
  * Run a batch send in a fail-safe manner.
  * This operates as Swift::batchSend() except it deals with errors itself.
  * @param Swift_Message To send
  * @param Swift_RecipientList Recipients (To: only)
  * @param Swift_Address The sender's address
  * @return int The number sent to
  */
 public function send(Swift_Message $message, Swift_RecipientList $recipients, $sender)
 {
     $sent = 0;
     $successive_fails = 0;
     $it = $recipients->getIterator("to");
     while ($it->hasNext()) {
         $it->next();
         $recipient = $it->getValue();
         $tried = 0;
         $loop = true;
         while ($loop && $tried < $this->getMaxTries()) {
             try {
                 $tried++;
                 $loop = false;
                 $this->copyMessageHeaders($message);
                 $sent += $n = $this->swift->send($message, $recipient, $sender);
                 if (!$n) {
                     $this->addFailedRecipient($recipient->getAddress());
                 }
                 $successive_fails = 0;
             } catch (Exception $e) {
                 $successive_fails++;
                 $this->restoreMessageHeaders($message);
                 if (($max = $this->getMaxSuccessiveFailures()) && $successive_fails > $max) {
                     throw new Exception("Too many successive failures. BatchMailer is configured to allow no more than " . $max . " successive failures.");
                 }
                 //If an exception was thrown, give it one more go
                 if ($t = $this->getSleepTime()) {
                     sleep($t);
                 }
                 $this->forceRestartSwift();
                 $loop = true;
             }
         }
     }
     return $sent;
 }
开发者ID:AlexanderS,项目名称:Part-DB,代码行数:45,代码来源:BatchMailer.php


示例14: Send

 public static function Send($id_lang, $template, $subject, $templateVars, $to, $toName = NULL, $from = NULL, $fromName = NULL, $fileAttachment = NULL, $modeSMTP = NULL, $templatePath = _PS_MAIL_DIR_)
 {
     $configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_SMTP_ENCRYPTION', 'PS_MAIL_SMTP_PORT', 'PS_MAIL_METHOD', 'PS_MAIL_TYPE'));
     if (!isset($configuration['PS_MAIL_SMTP_ENCRYPTION'])) {
         $configuration['PS_MAIL_SMTP_ENCRYPTION'] = "off";
     }
     if (!isset($configuration['PS_MAIL_SMTP_PORT'])) {
         $configuration['PS_MAIL_SMTP_PORT'] = "default";
     }
     if (!isset($from)) {
         $from = $configuration['PS_SHOP_EMAIL'];
     }
     if (!isset($fromName)) {
         $fromName = $configuration['PS_SHOP_NAME'];
     }
     if (!empty($from) and !Validate::isEmail($from) or !empty($fromName) and !Validate::isMailName($fromName) or !is_array($to) and !Validate::isEmail($to) or !empty($toName) and !Validate::isMailName($toName) or !is_array($templateVars) or !Validate::isTplName($template) or !Validate::isMailSubject($subject)) {
         die(Tools::displayError('Error: mail parameters are corrupted'));
     }
     /* Construct multiple recipients list if needed */
     if (is_array($to)) {
         $to_list = new Swift_RecipientList();
         foreach ($to as $key => $addr) {
             $to_name = NULL;
             $addr = trim($addr);
             if (!Validate::isEmail($addr)) {
                 die(Tools::displayError('Error: mail parameters are corrupted'));
             }
             if ($toName and is_array($toName) and Validate::isGenericName($toName[$key])) {
                 $to_name = $toName[$key];
             }
             $to_list->addTo($addr, $to_name);
         }
         $to_plugin = $to[0];
         $to = $to_list;
     } else {
         /* Simple recipient, one address */
         $to_plugin = $to;
         $to = new Swift_Address($to, $toName);
     }
     try {
         /* Connect with the appropriate configuration */
         if (intval($configuration['PS_MAIL_METHOD']) == 2) {
             $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']) and !empty($configuration['PS_MAIL_PASSWD'])) {
                 $connection->setUsername($configuration['PS_MAIL_USER']);
                 $connection->setPassword($configuration['PS_MAIL_PASSWD']);
             }
         } else {
             $connection = new Swift_Connection_NativeMail();
         }
         if (!$connection) {
             return false;
         }
         $swift = new Swift($connection);
         /* Get templates content */
         $iso = Language::getIsoById(intval($id_lang));
         if (!$iso) {
             die(Tools::displayError('Error - No iso code for email !'));
         }
         $template = $iso . '/' . $template;
         if (!file_exists($templatePath . $template . '.txt') or !file_exists($templatePath . $template . '.html')) {
             die(Tools::displayError('Error - The following email template is missing:') . ' ' . $templatePath . $template . '.txt');
         }
         $templateHtml = file_get_contents($templatePath . $template . '.html');
         $templateTxt = strip_tags(html_entity_decode(file_get_contents($templatePath . $template . '.txt'), NULL, 'utf-8'));
         include_once dirname(__FILE__) . '/../mails/' . $iso . '/lang.php';
         global $_LANGMAIL;
         /* Create mail and attach differents parts */
         $message = new Swift_Message('[' . Configuration::get('PS_SHOP_NAME') . '] ' . ((is_array($_LANGMAIL) and key_exists($subject, $_LANGMAIL)) ? $_LANGMAIL[$subject] : $subject));
         $templateVars['{shop_logo}'] = file_exists(_PS_IMG_DIR_ . 'logo.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_ . 'logo.jpg'))) : '';
         $templateVars['{shop_name}'] = htmlentities(Configuration::get('PS_SHOP_NAME'), NULL, 'utf-8');
         $templateVars['{shop_url}'] = 'http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__;
         $swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $templateVars)), 'decorator');
         if ($configuration['PS_MAIL_TYPE'] == 3 or $configuration['PS_MAIL_TYPE'] == 2) {
             $message->attach(new Swift_Message_Part($templateTxt, 'text/plain', '8bit', 'utf-8'));
         }
         if ($configuration['PS_MAIL_TYPE'] == 3 or $configuration['PS_MAIL_TYPE'] == 1) {
             $message->attach(new Swift_Message_Part($templateHtml, 'text/html', '8bit', 'utf-8'));
         }
         if ($fileAttachment and isset($fileAttachment['content']) and isset($fileAttachment['name']) and isset($fileAttachment['mime'])) {
             $message->attach(new Swift_Message_Attachment($fileAttachment['content'], $fileAttachment['name'], $fileAttachment['mime']));
         }
         /* Send mail */
         $send = $swift->send($message, $to, new Swift_Address($from, $fromName));
         $swift->disconnect();
         return $send;
     } catch (Swift_ConnectionException $e) {
         return false;
     }
 }
开发者ID:sealence,项目名称:local,代码行数:94,代码来源:Mail.php


示例15: 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;
 }
开发者ID:mediasadc,项目名称:alba,代码行数:29,代码来源:nahoMail.php


示例16: send_now


//.........这里部分代码省略.........
         Swift_ClassLoader::load('Swift_Connection_Multi');
         Swift_ClassLoader::load('Swift_Connection_SMTP');
         $pool = new Swift_Connection_Multi();
         // first choose method
         if ($fs->prefs['smtp_server']) {
             $split = explode(':', $fs->prefs['smtp_server']);
             $port = null;
             if (count($split) == 2) {
                 $fs->prefs['smtp_server'] = $split[0];
                 $port = $split[1];
             }
             // connection... SSL, TLS or none
             if ($fs->prefs['email_ssl']) {
                 $smtp = new Swift_Connection_SMTP($fs->prefs['smtp_server'], $port ? $port : SWIFT_SMTP_PORT_SECURE, SWIFT_SMTP_ENC_SSL);
             } else {
                 if ($fs->prefs['email_tls']) {
                     $smtp = new Swift_Connection_SMTP($fs->prefs['smtp_server'], $port ? $port : SWIFT_SMTP_PORT_SECURE, SWIFT_SMTP_ENC_TLS);
                 } else {
                     $smtp = new Swift_Connection_SMTP($fs->prefs['smtp_server'], $port);
                 }
             }
             if ($fs->prefs['smtp_user']) {
                 $smtp->setUsername($fs->prefs['smtp_user']);
                 $smtp->setPassword($fs->prefs['smtp_pass']);
             }
             if (defined('FS_SMTP_TIMEOUT')) {
                 $smtp->setTimeout(FS_SMTP_TIMEOUT);
             }
             $pool->addConnection($smtp);
         } else {
             Swift_ClassLoader::load('Swift_Connection_NativeMail');
             // a connection to localhost smtp server as fallback, discarded if there is no such thing available.
             $pool->addConnection(new Swift_Connection_SMTP());
             $pool->addConnection(new Swift_Connection_NativeMail());
         }
         $swift = new Swift($pool);
         if (isset($data['task_id'])) {
             $swift->attachPlugin(new NotificationsThread($data['task_id'], $emails, $db), 'MessageThread');
         }
         if (defined('FS_MAIL_DEBUG')) {
             $swift->log->enable();
             Swift_ClassLoader::load('Swift_Plugin_VerboseSending');
             $view = new Swift_Plugin_VerboseSending_DefaultView();
             $swift->attachPlugin(new Swift_Plugin_VerboseSending($view), "verbose");
         }
         $message = new Swift_Message($subject, $body);
         // check for reply-to
         if (isset($data['project']) && $data['project']->prefs['notify_reply']) {
             $message->setReplyTo($data['project']->prefs['notify_reply']);
         }
         if (isset($data['project']) && isset($data['project']->prefs['bounce_address'])) {
             $message->setReturnPath($data['project']->prefs['bounce_address']);
         }
         $message->headers->setCharset('utf-8');
         $message->headers->set('Precedence', 'list');
         $message->headers->set('X-Mailer', 'Flyspray');
         // Add custom headers, possibly
         if (isset($data['headers'])) {
             $headers = array_map('trim', explode("\n", $data['headers']));
             if ($headers = array_filter($headers)) {
                 foreach ($headers as $header) {
                     list($name, $value) = explode(':', $header);
                     $message->headers->set(sprintf('X-Flyspray-%s', $name), $value);
                 }
             }
         }
         $recipients = new Swift_RecipientList();
         $recipients->addTo($emails);
         // && $result purpose: if this has been set to false before, it should never become true again
         // to indicate an error
         $result = $swift->batchSend($message, $recipients, $fs->prefs['admin_email']) === count($emails) && $result;
         if (isset($data['task_id'])) {
             $plugin =& $swift->getPlugin('MessageThread');
             if (count($plugin->thread_info)) {
                 $stmt = $db->x->autoPrepare('{notification_threads}', array('task_id', 'recipient_id', 'message_id'));
                 $db->x->executeMultiple($stmt, $plugin->thread_info);
                 $stmt->free();
             }
         }
         $swift->disconnect();
     }
     if (count($jids)) {
         $jids = array_unique($jids);
         if (!$fs->prefs['jabber_username'] || !$fs->prefs['jabber_password']) {
             return $result;
         }
         // nothing that can't be guessed correctly ^^
         if (!$fs->prefs['jabber_port']) {
             $fs->prefs['jabber_port'] = 5222;
         }
         require_once 'class.jabber2.php';
         $jabber = new Jabber($fs->prefs['jabber_username'], $fs->prefs['jabber_password'], $fs->prefs['jabber_security'], $fs->prefs['jabber_port'], $fs->prefs['jabber_server']);
         $jabber->SetResource('flyspray');
         $jabber->login();
         foreach ($jids as $jid) {
             $result = $jabber->send_message($jid, $body, $subject, 'normal') && $result;
         }
     }
     return $result;
 }
开发者ID:negram,项目名称:flyspray,代码行数:101,代码来源:class.notify.php


示例17: sendBatch

 public static function sendBatch(array $emails, $subject, $message)
 {
     if (empty($subject) || empty($msg) || empty($emails)) {
         return false;
     }
     $obj = new self();
     $from = $obj->fromEmail;
     $fromName = $obj->fromName;
     require_once SITE_ROOT . "/php/lib/Swift.php";
     require_once SITE_ROOT . "/php/lib/Swift/Connection/SMTP.php";
     require_once SITE_ROOT . "/php/lib/Swift/RecipientList.php";
     require_once SITE_ROOT . "/php/lib/Swift/BatchMailer.php";
     try {
         //Start Swift
         $swift = new Swift(new Swift_Connection_SMTP(defined('SMTP_SERVER') ? SMTP_SERVER : '127.0.0.1:25'));
         //Create the message
         $message = new Swift_Message($subject, $msg);
         //customize names
         $recips = new Swift_RecipientList();
         foreach ($emails as $email) {
             $recips->addTo($email);
         }
         $from = new Swift_Address($from, $fromName);
         //Now check if Swift actually sends it
         if ($swift->sendBatch($message, $recips, $from)) {
             $log = "sent mail to: " . var_export($emails, true) . "\n";
             $ret = true;
         }
     } catch (Swift_ConnectionException $e) {
         $ret = false;
         $log = "There was a problem communicating with SMTP: " . $e->getMessage() . "\n";
     } catch (Swift_Message_MimeException $e) {
         $ret = false;
         $log = "There was an unexpected problem building the email:" . $e->getMessage() . "\n";
     }
     return $ret;
 }
开发者ID:soldair,项目名称:solumLite,代码行数:37,代码来源:email.class.php


示例18: mass_mailer

 /**
  * 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
 }

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Swift_SendmailTransport类代码示例发布时间:2022-05-23
下一篇:
PHP Swift_Preferences类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap