当前位置: 首页>>代码示例>>PHP>>正文


PHP Swift_RecipientList::addTo方法代码示例

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


在下文中一共展示了Swift_RecipientList::addTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: send_email

 private function send_email($email, $subject, $content)
 {
     $swift = email::connect();
     $from = 'no-reply@uwdata.ca';
     $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

示例6: 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

示例7: 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

示例8: 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

示例9: inviteNewUser

 private function inviteNewUser($email, $mailer)
 {
     $username = md5(rand(1000, 9999));
     $password = md5(rand(1000, 9999));
     $user = new sfGuardUser();
     $user->username = $username;
     $user->password = $password;
     $user->groups[] = Doctrine::getTable('sfGuardGroup')->createQuery('a')->where('a.name = ?', 'leerling')->fetchOne();
     $user->Profile = new sfGuardUserProfile();
     $user->Profile->email = $email;
     $user->Profile->is_invite = true;
     $user->save();
     $user->Profile->save();
     $name = sprintf('%s (%s)', $this->getUser()->getGuardUser()->getFullname(), $this->getUser()->getUsername());
     $url = $this->getController()->genUrl(sprintf('@invite_accept?username=%s', $username), true);
     $message = new Swift_Message();
     $message->setFrom('DNS Leergemeenschap Site');
     $message->setSubject('Uitnodiging DNS Leergemeenschap');
     $message->setContentType('text/html');
     $message->setBody("Hallo, <br /><br />\n\nJij bent door {$name} uitgenodigd om deel te nemen aan de de DNS Leergemeenschap site.<br /><br />\n\n<a href=\"{$url}\">Klik hier om de uitnodiging aan te nemen</a><br /><br /><br /><br /><br /><br />\n\n{$url}");
     $recipients = new Swift_RecipientList();
     foreach (sfConfig::get('app_feedback_feedback_email', array('dnsleergemeenschap@gmail.com')) as $recipient) {
         $recipients->addTo($recipient);
     }
     $mailer->send($message, $recipients, $this->getUser()->getEmail());
 }
开发者ID:robinkanters,项目名称:dnsleergemeenschap,代码行数:26,代码来源:actions.class.php

示例10: config_email_save

 /**
  * Save the results of a configuration of emails form, unless the skip button was clicked
  * in which case the user is redirected to a page allowing them to confirm this.
  */
 public function config_email_save()
 {
     if (isset($_POST['skip'])) {
         url::redirect('setup_check/skip_email');
     } else {
         $source = dirname(dirname(__FILE__)) . '/config_files/_email.php';
         $dest = dirname(dirname(dirname(dirname(__FILE__)))) . "/application/config/email.php";
         try {
             unlink($dest);
         } catch (Exception $e) {
             // file doesn't exist?'
         }
         try {
             $_source_content = file_get_contents($source);
             // Now save the POST form values into the config file
             foreach ($_POST as $field => $value) {
                 $_source_content = str_replace("*{$field}*", $value, $_source_content);
             }
             file_put_contents($dest, $_source_content);
             // Test the email config
             $swift = email::connect();
             $message = new Swift_Message('Setup test', Kohana::lang('setup.test_email_title'), 'text/html');
             $recipients = new Swift_RecipientList();
             $recipients->addTo($_POST['test_email']);
             if ($swift->send($message, $recipients, $_POST['address']) == 1) {
                 $_source_content = str_replace("*test_result*", 'pass', $_source_content);
                 file_put_contents($dest, $_source_content);
                 url::redirect('setup_check');
             } else {
                 $this->error = Kohana::lang('setup.test_email_failed');
                 $this->config_email();
             }
         } catch (Exception $e) {
             // Swift mailer messages tend to have the error message as the last part, with each part colon separated.
             $msg = explode(':', $e->getMessage());
             $this->error = $msg[count($msg) - 1];
             kohana::log('error', $e->getMessage());
             $this->config_email();
         }
     }
 }
开发者ID:BirenRathod,项目名称:indicia-code,代码行数:45,代码来源:setup_check.php

示例11: 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

示例12: 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

示例13: Send

 /**
  * Send Email
  * 
  * @param int $id_lang Language of the email (to translate the template)
  * @param string $template Template: the name of template not be a var but a string !
  * @param string $subject
  * @param string $template_vars
  * @param string $to
  * @param string $to_name
  * @param string $from
  * @param string $from_name
  * @param array $file_attachment Array with three parameters (content, mime and name). You can use an array of array to attach multiple files
  * @param bool $modeSMTP
  * @param string $template_path
  * @param bool $die
  * @param string $bcc Bcc recipient
  */
 public static function Send($id_lang, $template, $subject, $template_vars, $to, $to_name = null, $from = null, $from_name = null, $file_attachment = null, $mode_smtp = null, $template_path = _PS_MAIL_DIR_, $die = false, $id_shop = null, $bcc = null)
 {
     $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_TYPE'), null, null, $id_shop);
     // Returns immediatly if emails are deactivated
     if ($configuration['PS_MAIL_METHOD'] == 3) {
         return true;
     }
     $theme_path = _PS_THEME_DIR_;
     // Get the path of theme by id_shop if exist
     if (is_numeric($id_shop) && $id_shop) {
         $shop = new Shop((int) $id_shop);
         $theme_name = $shop->getTheme();
         if (_THEME_NAME_ != $theme_name) {
             $theme_path = _PS_ROOT_DIR_ . '/themes/' . $theme_name . '/';
         }
     }
     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';
     }
     // Sending an e-mail can be of vital importance for the merchant, when his password is lost for example, so we must not die but do our best to send the e-mail
     if (!isset($from) || !Validate::isEmail($from)) {
         $from = $configuration['PS_SHOP_EMAIL'];
     }
     if (!Validate::isEmail($from)) {
         $from = null;
     }
     // $from_name is not that important, no need to die if it is not valid
     if (!isset($from_name) || !Validate::isMailName($from_name)) {
         $from_name = $configuration['PS_SHOP_NAME'];
     }
     if (!Validate::isMailName($from_name)) {
         $from_name = null;
     }
     // It would be difficult to send an e-mail if the e-mail is not valid, so this time we can die if there is a problem
     if (!is_array($to) && !Validate::isEmail($to)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "to" is corrupted'), $die);
         return false;
     }
     if (!is_array($template_vars)) {
         $template_vars = array();
     }
     // Do not crash for this error, that may be a complicated customer name
     if (is_string($to_name) && !empty($to_name) && !Validate::isMailName($to_name)) {
         $to_name = null;
     }
     if (!Validate::isTplName($template)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid e-mail template'), $die);
         return false;
     }
     if (!Validate::isMailSubject($subject)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid e-mail subject'), $die);
         return false;
     }
     /* Construct multiple recipients list if needed */
     $to_list = new Swift_RecipientList();
     if (is_array($to) && isset($to)) {
         foreach ($to as $key => $addr) {
             $addr = trim($addr);
             if (!Validate::isEmail($addr)) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid e-mail address'), $die);
                 return false;
             }
             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 {
//.........这里部分代码省略.........
开发者ID:dev-lav,项目名称:htdocs,代码行数:101,代码来源:Mail.php

示例14: Send

 public static function Send($template, $subject, $templateVars, $to, $toName = null, $from = null, $fromName = null, $fileAttachment = null, $modeSMTP = null, $templatePath = null, $die = false)
 {
     $configuration = Configuration::getMultiple(array('TM_SHOP_EMAIL', 'TM_MAIL_METHOD', 'TM_MAIL_SERVER', 'TM_MAIL_USER', 'TM_MAIL_PASSWD', 'TM_SHOP_NAME', 'TM_MAIL_SMTP_ENCRYPTION', 'TM_MAIL_SMTP_PORT', 'TM_MAIL_METHOD'));
     if (!isset($configuration['TM_MAIL_SMTP_ENCRYPTION'])) {
         $configuration['TM_MAIL_SMTP_ENCRYPTION'] = 'off';
     }
     if (!isset($configuration['TM_MAIL_SMTP_PORT'])) {
         $configuration['TM_MAIL_SMTP_PORT'] = 'default';
     }
     if (!isset($from)) {
         $from = $configuration['TM_SHOP_EMAIL'];
     }
     if (!isset($fromName)) {
         $fromName = $configuration['TM_SHOP_NAME'];
     }
     if (!empty($from) && !Validate::isEmail($from)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "from" is corrupted'), $die);
         return false;
     }
     if (!empty($fromName) && !Validate::isMailName($fromName)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "fromName" is corrupted'), $die);
         return false;
     }
     if (!is_array($to) && !Validate::isEmail($to)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "to" is corrupted'), $die);
         return false;
     }
     if (!is_array($templateVars)) {
         Tools::dieOrLog(Tools::displayError('Error: parameter "templateVars" is not an array'), $die);
         return false;
     }
     // Do not crash for this error, that may be a complicated customer name
     if (is_string($toName)) {
         if (!empty($toName) && !Validate::isMailName($toName)) {
             $toName = null;
         }
     }
     if (!Validate::isTplName($template)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid email template'), $die);
         return false;
     }
     if (!Validate::isMailSubject($subject)) {
         Tools::dieOrLog(Tools::displayError('Error: invalid email subject'), $die);
         return false;
     }
     /* Construct multiple recipients list if needed */
     if (isset($to) && is_array($to)) {
         $to_list = new Swift_RecipientList();
         foreach ($to as $key => $addr) {
             $to_name = null;
             $addr = trim($addr);
             if (!Validate::isEmail($addr)) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid email address'), $die);
                 return false;
             }
             if (is_array($toName)) {
                 if ($toName && is_array($toName) && Validate::isGenericName($toName[$key])) {
                     $to_name = $toName[$key];
                 }
             }
             $to_list->addTo($addr, base64_encode($to_name));
         }
         $to_plugin = $to[0];
         $to = $to_list;
     } else {
         /* Simple recipient, one address */
         $to_plugin = $to;
         $to = new Swift_Address($to, base64_encode($toName));
     }
     try {
         /* Connect with the appropriate configuration */
         if ($configuration['TM_MAIL_METHOD'] == 2) {
             if (empty($configuration['TM_MAIL_SERVER']) || empty($configuration['TM_MAIL_SMTP_PORT'])) {
                 Tools::dieOrLog(Tools::displayError('Error: invalid SMTP server or SMTP port'), $die);
                 return false;
             }
             $connection = new Swift_Connection_SMTP($configuration['TM_MAIL_SERVER'], $configuration['TM_MAIL_SMTP_PORT'], $configuration['TM_MAIL_SMTP_ENCRYPTION'] == 'ssl' ? Swift_Connection_SMTP::ENC_SSL : ($configuration['TM_MAIL_SMTP_ENCRYPTION'] == 'tls' ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF));
             $connection->setTimeout(20);
             if (!$connection) {
                 return false;
             }
             if (!empty($configuration['TM_MAIL_USER'])) {
                 $connection->setUsername($configuration['TM_MAIL_USER']);
             }
             if (!empty($configuration['TM_MAIL_PASSWD'])) {
                 $connection->setPassword($configuration['TM_MAIL_PASSWD']);
             }
         } else {
             $connection = new Swift_Connection_NativeMail();
         }
         if (!$connection) {
             return false;
         }
         $swift = new Swift($connection, Configuration::get('TM_MAIL_DOMAIN'));
         // get templatePath
         $templatePath = _TM_THEMES_DIR . 'mails/';
         $templateHtml = file_get_contents($templatePath . $template . '.html');
         /* Create mail && attach differents parts */
         $message = new Swift_Message('[' . Configuration::get('TM_SHOP_NAME') . '] ' . $subject);
         $templateVars['{shop_logo}'] = file_exists(_TM_IMG_DIR . 'logo_mail.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_TM_IMG_DIR . 'logo_mail.jpg'))) : (file_exists(_TM_IMG_DIR . 'logo.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_TM_IMG_DIR . 'logo.jpg'))) : '');
//.........这里部分代码省略.........
开发者ID:yiuked,项目名称:tmcart,代码行数:101,代码来源:Mail.php

示例15: array


//.........这里部分代码省略.........
         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


注:本文中的Swift_RecipientList::addTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。