Exemplo n.º 1
0
    /**
     * Init mail transport
     *
     * @return Zend_Mail_Transport_Abstract
     */
    protected function initMailTransport()
    {
        $options = Shopware()->getOption('mail') ? Shopware()->getOption('mail') : array();
        $config = $this->getResource('Config');

        if (!isset($options['type']) && !empty($config->MailerMailer) && $config->MailerMailer!='mail') {
            $options['type'] = $config->MailerMailer;
        }
        if (empty($options['type'])) {
            $options['type'] = 'sendmail';
        }

        if ($options['type'] == 'smtp') {
            if (!isset($options['username']) && !empty($config->MailerUsername)) {
                if (!empty($config->MailerAuth)) {
                    $options['auth'] = $config->MailerAuth;
                } elseif (empty($options['auth'])) {
                    $options['auth'] = 'login';
                }
                $options['username'] = $config->MailerUsername;
                $options['password'] = $config->MailerPassword;
            }
            if (!isset($options['ssl']) && !empty($config->MailerSMTPSecure)) {
                $options['ssl'] = $config->MailerSMTPSecure;
            }
            if (!isset($options['port']) && !empty($config->MailerPort)) {
                $options['port'] = $config->MailerPort;
            }
            if (!isset($options['name']) && !empty($config->MailerHostname)) {
                $options['name'] = $config->MailerHostname;
            }
            if (!isset($options['host']) && !empty($config->MailerHost)) {
                $options['host'] = $config->MailerHost;
            }
        }

        if (!Shopware()->Loader()->loadClass($options['type'])) {
            $transportName = ucfirst(strtolower($options['type']));
            $transportName = 'Zend_Mail_Transport_'.$transportName;
        } else {
            $transportName = $options['type'];
        }
        unset($options['type'], $options['charset']);

        if ($transportName=='Zend_Mail_Transport_Smtp') {
            $transport = Enlight_Class::Instance($transportName, array($options['host'], $options));
        } elseif (!empty($options)) {
            $transport = Enlight_Class::Instance($transportName, array($options));
        } else {
            $transport = Enlight_Class::Instance($transportName);
        }
        Enlight_Components_Mail::setDefaultTransport($transport);

        if (!isset($options['from']) && !empty($config->Mail)) {
            $options['from'] = array('email'=>$config->Mail, 'name'=>$config->Shopname);
        }

        if (!empty($options['from']['email'])) {
            Enlight_Components_Mail::setDefaultFrom(
                $options['from']['email'],
                !empty($options['from']['name']) ? $options['from']['name'] : null
            );
        }
        if (!empty($options['replyTo']['email'])) {
            Enlight_Components_Mail::setDefaultReplyTo(
                $options['replyTo']['email'],
                !empty($options['replyTo']['name']) ? $options['replyTo']['name'] : null
            );
        }

        return $transport;
    }
Exemplo n.º 2
0
 /**
  * @param \Enlight_Loader               $loader
  * @param \Shopware_Components_Config   $config
  * @param array                         $options
  * @return \Enlight_Class|\Zend_Mail_Transport_Abstract
  */
 public function factory(\Enlight_Loader $loader, \Shopware_Components_Config $config, array $options)
 {
     if (!isset($options['type']) && !empty($config->MailerMailer) && $config->MailerMailer != 'mail') {
         $options['type'] = $config->MailerMailer;
     }
     if (empty($options['type'])) {
         $options['type'] = 'sendmail';
     }
     if ($options['type'] == 'smtp') {
         if (!isset($options['username']) && !empty($config->MailerUsername)) {
             if (!empty($config->MailerAuth)) {
                 $options['auth'] = $config->MailerAuth;
             } elseif (empty($options['auth'])) {
                 $options['auth'] = 'login';
             }
             $options['username'] = $config->MailerUsername;
             $options['password'] = $config->MailerPassword;
         }
         if (!isset($options['ssl']) && !empty($config->MailerSMTPSecure)) {
             $options['ssl'] = $config->MailerSMTPSecure;
         }
         if (!isset($options['port']) && !empty($config->MailerPort)) {
             $options['port'] = $config->MailerPort;
         }
         if (!isset($options['name']) && !empty($config->MailerHostname)) {
             $options['name'] = $config->MailerHostname;
         }
         if (!isset($options['host']) && !empty($config->MailerHost)) {
             $options['host'] = $config->MailerHost;
         }
     }
     if (!$loader->loadClass($options['type'])) {
         $transportName = ucfirst(strtolower($options['type']));
         $transportName = 'Zend_Mail_Transport_' . $transportName;
     } else {
         $transportName = $options['type'];
     }
     unset($options['type'], $options['charset']);
     if ($transportName == 'Zend_Mail_Transport_Smtp') {
         $transport = \Enlight_Class::Instance($transportName, array($options['host'], $options));
     } elseif (!empty($options)) {
         $transport = \Enlight_Class::Instance($transportName, array($options));
     } else {
         $transport = \Enlight_Class::Instance($transportName);
     }
     /** @var $transport \Zend_Mail_Transport_Abstract */
     \Enlight_Components_Mail::setDefaultTransport($transport);
     if (!isset($options['from']) && !empty($config->Mail)) {
         $options['from'] = array('email' => $config->Mail, 'name' => $config->Shopname);
     }
     if (!empty($options['from']['email'])) {
         \Enlight_Components_Mail::setDefaultFrom($options['from']['email'], !empty($options['from']['name']) ? $options['from']['name'] : null);
     }
     if (!empty($options['replyTo']['email'])) {
         \Enlight_Components_Mail::setDefaultReplyTo($options['replyTo']['email'], !empty($options['replyTo']['name']) ? $options['replyTo']['name'] : null);
     }
     return $transport;
 }