setDefaultTransport() public static méthode

Sets the default mail transport for all following uses of Zend_Mail::send();
public static setDefaultTransport ( Zend_Mail_Transport_Abstract $transport )
$transport Zend_Mail_Transport_Abstract
 /**
  * @return Zend_Mail
  * @throws Zend_Mail_Protocol_Exception
  */
 public static function getMail(Users_Model_User $user, $subject)
 {
     $file = CommunityID_Resources::getResourcePath('reminder_mail.txt');
     $emailTemplate = file_get_contents($file);
     $emailTemplate = str_replace('{userName}', $user->getFullName(), $emailTemplate);
     $currentUrl = Zend_OpenId::selfURL();
     preg_match('#(.*)/manageusers/sendreminder#', $currentUrl, $matches);
     $emailTemplate = str_replace('{registrationURL}', $matches[1] . '/register/eula?token=' . $user->token, $emailTemplate);
     // can't use $this->_config 'cause it's a static function
     $configEmail = Zend_Registry::get('config')->email;
     switch (strtolower($configEmail->transport)) {
         case 'smtp':
             Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Smtp($configEmail->host, $configEmail->toArray()));
             break;
         case 'mock':
             Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Mock());
             break;
         default:
             Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Sendmail());
     }
     $mail = new Zend_Mail('UTF-8');
     $mail->setBodyText($emailTemplate);
     $mail->setFrom($configEmail->supportemail);
     $mail->addTo($user->email);
     $mail->setSubject($subject);
     return $mail;
 }
Exemple #2
0
 /**
  * Will set the Default Transport object for the mail object based on the supplied accountname
  *
  * @param string $accountName
  * @return boolean TRUE/FALSE
  */
 public function useAccount($accountName)
 {
     //If a mail object exists, overwrite with new object
     if ($this->_mail) {
         $this->_constructMail();
     }
     $this->m_UseAccount = $accountName;
     $account = $this->m_Accounts->get($accountName);
     if ($account->m_IsSMTP == "Y") {
         require_once 'Zend/Mail/Transport/Smtp.php';
         if ($account->m_SMTPAuth == "Y") {
             $config = array('auth' => 'login', 'username' => $account->m_Username, 'password' => $account->m_Password, "port" => $account->m_Port, 'ssl' => $account->m_SSL);
         } else {
             $config = array();
         }
         $mailTransport = new Zend_Mail_Transport_Smtp($account->m_Host, $config);
         $this->_mail->setDefaultTransport($mailTransport);
     } else {
         require_once 'Zend/Mail/Transport/Sendmail.php';
         $mailTransport = new Zend_Mail_Transport_Sendmail();
         $this->_mail->setDefaultTransport($mailTransport);
     }
     $this->_mail->setFrom($account->m_FromEmail, $account->m_FromName);
     return $this;
 }
 public static function sendMail($content)
 {
     $front = Zend_Controller_Front::getInstance();
     $email = new Base_Php_Overloader($front->getParam("bootstrap")->getOption('smtp'));
     $smtp = $email->domain;
     $username = $email->username;
     $password = $email->password;
     $port = $email->port;
     $config = new Zend_Mail_Transport_Smtp($smtp, array('auth' => 'login', 'username' => $username, 'password' => $password, 'ssl' => "ssl", 'port' => $port));
     Zend_Mail::setDefaultTransport($config);
     $mail = new Zend_Mail('UTF-8');
     $mail->setBodyHtml($content['body']);
     // Email body
     $mail->setFrom($content['sender'], $content['nameSender']);
     // Sender (Email, Name)
     $mail->addTo(isset($content['recipient']) ? $content['recipient'] : '', isset($content['nameRecipient']) ? $content['nameRecipient'] : '');
     // Recipient (Email, Name)
     $mail->addCc($content['sender'], $content['nameSender']);
     // CC to // Reply to Sender
     $mail->setSubject($content['subject']);
     // Subject Email
     try {
         $flag = $mail->send($config);
     } catch (Zend_Exception $e) {
         Base_Helper_Log::getInstance()->log(PHP_EOL . date('H:i:s :::: ') . ' [MAIL] ' . $e->getMessage());
         $flag = false;
     }
     if ($flag) {
         return true;
     } else {
         return false;
     }
 }
 public function sendMail()
 {
     if (func_num_args() >= 4) {
         $to = func_get_arg(0);
         $from = func_get_arg(1);
         $subject = func_get_arg(2);
         $messageRecieved = func_get_arg(3);
         $tr = new Zend_Mail_Transport_Smtp($this->_host, array('auth' => 'login', 'username' => $this->_username, 'password' => $this->_password, 'port' => $this->_port));
         Zend_Mail::setDefaultTransport($tr);
         $mail = new Zend_Mail('utf-8');
         $mail->setFrom($from);
         $mail->setBodyHtml($messageRecieved);
         $mail->addTo($to);
         $mail->setSubject($subject);
         $mail->addHeader('MIME-Version', '1.0');
         $mail->addHeader('Content-Transfer-Encoding', '8bit');
         $mail->addHeader('X-Mailer:', 'PHP/' . phpversion());
         try {
             $mail->send();
             $response = "Mail sent";
             return $response;
         } catch (Exception $e) {
             throw new Zend_Controller_Action_Exception('SendGrid Mail sending error', 500);
         }
     } else {
         throw new Zend_Controller_Action_Exception('Paramter Not passed', 500);
     }
 }
 public function indexAction()
 {
     $form = new Application_Form_FaleConoscoForm();
     $this->view->form = $form;
     $params = $this->_request->getParams();
     if ($this->_request->isPost() && $form->isValid($params)) {
         try {
             $vista = Services::get('vista_rest');
             $vista->getAuthEmail();
             $smtpData = $vista->getResult();
             $config = array('auth' => 'login', 'username' => $smtpData['user'], 'password' => $smtpData['pass'], 'port' => $smtpData['port']);
             $transport = new Zend_Mail_Transport_Smtp($smtpData['smtp'], $config);
             Zend_Mail::setDefaultTransport($transport);
             $html = new Zend_View();
             $html->setScriptPath(APPLICATION_PATH . '/views/scripts/fale-conosco/');
             $html->data = $params;
             $emailBody = $html->render('email-body.phtml');
             $mail = new Zend_Mail();
             $mail->setBodyHtml($emailBody);
             $mail->setFrom('*****@*****.**', $params['nome']);
             $mail->addTo('*****@*****.**', 'Esselence');
             $mail->setSubject("Contato pelo Site {$params['nome']}");
             $mail->send();
             $this->view->success = true;
         } catch (Exception $e) {
             print_r($e->getMessage());
             exit;
         }
     }
 }
 public function indexAction()
 {
     do {
         $message = App_Model_Queue::pop(App_Model_Queue::EMAIL);
         if ($message) {
             $user = App_Model_User::fetchOne(['id' => (string) $message->user]);
             $config = $user->data['mail'];
             Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Smtp($config['server'], ['auth' => $config['auth'], 'username' => $config['username'], 'password' => $config['password'], 'port' => $config['port'], 'ssl' => $config['ssl']]));
             $mail = new Zend_Mail('UTF-8');
             foreach ($message->receivers as $receiver) {
                 $mail->addTo($receiver['email'], $receiver['name']);
             }
             $this->writeLine("------------------------------------------------");
             $this->writeLine("to: " . print_r($message->receivers, true));
             $this->writeLine("from: " . implode(', ', [$user->data['mail']['username'], $user->data['mail']['name']]));
             $this->writeLine("Subject: " . $message->subject);
             $mail->setSubject($message->subject);
             $mail->setBodyHtml($message->content);
             $mail->setFrom($user->data['mail']['username'], $user->data['mail']['name']);
             $this->writeLine("Start sending...");
             try {
                 $mail->send();
             } catch (Exception $e) {
                 $this->writeLine($e->getMessage());
             }
             $this->writeLine('>>>> Done');
             sleep(1);
         }
     } while (true);
 }
Exemple #7
0
 public function sendEmail($template, $to, $subject, $params = array())
 {
     try {
         $config = array('auth' => 'Login', 'port' => $this->_bootstrap_options['mail']['port'], 'ssl' => 'ssl', 'username' => $this->_bootstrap_options['mail']['username'], 'password' => $this->_bootstrap_options['mail']['password']);
         $tr = new Zend_Mail_Transport_Smtp($this->_bootstrap_options['mail']['server'], $config);
         Zend_Mail::setDefaultTransport($tr);
         $mail = new Zend_Mail('UTF-8');
         $layout = new Zend_Layout();
         $layout->setLayoutPath($this->_bootstrap_options['mail']['layout']);
         $layout->setLayout('email');
         $view = $layout->getView();
         $view->domain_url = $this->_bootstrap_options['site']['domainurl'];
         $view = new Zend_View();
         $view->params = $params;
         $view->setScriptPath($this->_bootstrap_options['mail']['view_script']);
         $layout->content = $view->render($template . '.phtml');
         $content = $layout->render();
         $mail->setBodyText(preg_replace('/<[^>]+>/', '', $content));
         $mail->setBodyHtml($content);
         $mail->setFrom($this->_bootstrap_options['mail']['from'], $this->_bootstrap_options['mail']['from_name']);
         $mail->addTo($to);
         $mail->setSubject($subject);
         $mail->send();
     } catch (Exception $e) {
         // 这里要完善
     }
     return true;
 }
Exemple #8
0
 public function __construct()
 {
     $this->_transport = new Zend_Mail_Transport_Smtp($this->_smtp_server, $this->_config);
     Zend_Mail::setDefaultTransport($this->_transport);
     //$this->_mail = new Zend_Mail('UTF-8');
     $this->_mail = new TS_Mail_Model();
 }
Exemple #9
0
    /**
     *
     * @return Zend_Mail_Transport_Abstract|null
     */
    public function getMail()
    {
        if (null === $this->_transport) {
            $options = $this->getOptions();
            foreach($options as $key => $option) {
                $options[strtolower($key)] = $option;
            }
            $this->setOptions($options);

            if(isset($options['transport']) &&
               !is_numeric($options['transport']))
            {
                $this->_transport = $this->_setupTransport($options['transport']);
                if(!isset($options['transport']['register']) ||
                   $options['transport']['register'] == '1' ||
                   (isset($options['transport']['register']) &&
                        !is_numeric($options['transport']['register']) &&
                        (bool) $options['transport']['register'] == true))
                {
                    Zend_Mail::setDefaultTransport($this->_transport);
                }
            }

            $this->_setDefaults('from');
            $this->_setDefaults('replyTo');
        }

        return $this->_transport;
    }
     $this->_moduleName = Zend_Controller_Front::getInstance()->getRequest()->getModuleName();
     $this->view->moduleName = $this->_moduleName;
     //        echo $this->_moduleName;exit;
     // Breadcrumb
     $this->_generateBreadcrumb();
     // Title dari website
     // Nama controller
     $this->view->controller = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
     // Nama action
     $this->view->action = Zend_Controller_Front::getInstance()->getRequest()->getActionName();
     $this->view->sess = $this->_sess;
     //generate header image
     $highlightDb = new Model_DbTable_Highlight();
     $highlight = $highlightDb->getMainType(3, $this->_languageId);
     $this->view->imageData = $highlight;
     // Untuk munculin list kategori di menu
     $categoryDb = new Model_Category();
     $categories = $categoryDb->getAllHierarchyByLanguage();
     $this->view->categories = $categories;
     $this->view->headTitle('Kebudayaan Indonesia');
     $partnerDb = new Model_DbTable_Partner();
     //        Data
     $partner = $partnerDb->getAllWithDesc($this->_languageId);
     $partner = $partnerDb->fetchAll($partner);
     $this->view->partner = $partner->toArray();
     //        echo '<pre>';
     //        print_r($categories);
 }
 /**
  * Fungsi untuk generate breadcrumb. Fungsi ini akan di-override sama
  * controller anak2nya. Disengaja untuk dikosongin
  */
 protected function _generateBreadcrumb()
 {
    /**
     * @return Zend_Mail
     * @throws Zend_Mail_Protocol_Exception
     */
    public static function getMail($name, $email, $feedback)
    {
        // can't use $this-_config 'cause it's a static function
        $configEmail = Zend_Registry::get('config')->email;
        switch (strtolower($configEmail->transport)) {
            case 'smtp':
                Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Smtp($configEmail->host, $configEmail->toArray()));
                break;
            case 'mock':
                Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Mock());
                break;
            default:
                Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Sendmail());
        }
        $mail = new Zend_Mail('UTF-8');
        $mail->setBodyText(<<<EOD
Dear Administrator,

The community-id feedback form has just been used to send you the following:

Name: {$name}
E-mail: {$email}
Feedback:
{$feedback}
EOD
);
        $mail->setFrom($configEmail->supportemail);
        $mail->addTo($configEmail->supportemail);
        $mail->setSubject('Community-ID feedback form');
        return $mail;
    }
Exemple #12
0
 protected function _initEmail()
 {
     $email_config = array('auth' => 'plain', 'username' => '*****@*****.**', 'password' => 'vikucia1994', 'ssl' => 'ssl');
     //створюємо транспорт
     $transport = new Zend_Mail_Transport_Smtp('*****@*****.**', $email_config);
     Zend_Mail::setDefaultTransport($transport);
 }
Exemple #13
0
function tiki_mail_setup()
{
    static $done = false;
    if ($done) {
        return;
    }
    global $prefs;
    if ($prefs['zend_mail_handler'] == 'smtp') {
        $options = array();
        if ($prefs['zend_mail_smtp_auth']) {
            $options['auth'] = $prefs['zend_mail_smtp_auth'];
            $options['username'] = $prefs['zend_mail_smtp_user'];
            $options['password'] = $prefs['zend_mail_smtp_pass'];
        }
        if ($prefs['zend_mail_smtp_port']) {
            $options['port'] = $prefs['zend_mail_smtp_port'];
        }
        if ($prefs['zend_mail_smtp_security']) {
            $options['ssl'] = $prefs['zend_mail_smtp_security'];
        }
        $transport = new Zend_Mail_Transport_Smtp($prefs['zend_mail_smtp_server'], $options);
        Zend_Mail::setDefaultTransport($transport);
    }
    $done = true;
}
Exemple #14
0
 /**
  * Send email
  *
  * TODO: add language specific template based on recepient default language
  */
 public static function sendEmail($to, $subject, $body, $show_errors = false)
 {
     if (Zend_Registry::get('config')->get('mail_adapter') == 'smtp') {
         $smtp_config = array('ssl' => Zend_Registry::get('config')->get('mail_security'), 'port' => Zend_Registry::get('config')->get('mail_port'), 'auth' => Zend_Registry::get('config')->get('mail_login'), 'username' => Zend_Registry::get('config')->get('mail_username'), 'password' => Zend_Registry::get('config')->get('mail_password'));
         $tr = new Zend_Mail_Transport_Smtp(Zend_Registry::get('config')->get('mail_host'), $smtp_config);
     } else {
         $tr = new Zend_Mail_Transport_Sendmail();
     }
     Zend_Mail::setDefaultTransport($tr);
     $mail = new Zend_Mail('utf8');
     $mail->setBodyHtml($body);
     $mail->setFrom(Zend_Registry::get('config')->get('mail_from'), Zend_Registry::get('config')->get('mail_from_name'));
     $mail->addTo($to);
     $mail->setSubject($subject);
     try {
         $mail->send($tr);
     } catch (Zend_Mail_Exception $e) {
         if (method_exists($tr, 'getConnection') && method_exists($tr->getConnection(), 'getLog')) {
             Application_Plugin_Common::log(array($e->getMessage(), $tr->getConnection()->getLog()));
         } else {
             Application_Plugin_Common::log(array($e->getMessage(), 'error sending mail'));
         }
         if ($show_errors) {
             Application_Plugin_Alerts::error(Zend_Registry::get('Zend_Translate')->translate('Something went wrong, email was not sent.'), 'off');
         }
         return false;
     }
     return true;
 }
 /**
  * sends a standard email
  * 
  * @param string $subject
  * @param string $toName
  * @param array $toEmails
  * @param array $emailOptions
  * @param string $fromName
  * @param string $fromEmail
  */
 public function send($subject, $toName, $toEmails = array(), $emailOptions = array(), $fromName = null, $fromEmail = null)
 {
     $logger = Zend_Registry::get('logger');
     $config = vkNgine_Config::getSystemConfig()->mail;
     if ($config->serverType == 'smtp') {
         $tr = new Zend_Mail_Transport_Smtp($config->server, $config->toArray());
     }
     Zend_Mail::setDefaultTransport($tr);
     foreach ($toEmails as $email) {
         $mail = new Zend_Mail();
         if ($emailOptions['type'] == 'html') {
             $mail->setBodyHtml($emailOptions['email']);
         } else {
             $mail->setBodyText($emailOptions['email']);
         }
         if (!$fromName || !$fromEmail) {
             $mail->setFrom($config->noreply, 'GYM Tracker');
         } else {
             $mail->setFrom($fromEmail, $fromName);
         }
         $mail->addTo($email, $toName);
         $mail->setSubject($subject);
         try {
             $mail->send();
         } catch (Zend_Mail_Protocol_Exception $e) {
             $logger->log('MESSAGE_SEND_FAILED', 'Unable to send to ' . $email . ' - ' . $e->getMessage(), 1);
         }
     }
 }
Exemple #16
0
 public function saveFiles($fileArray)
 {
     if (empty($fileArray)) {
         return array();
     }
     // Init connection
     $this->initConnection();
     $savedFiles = array();
     @ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
     @ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
     $charset = "utf-8";
     #$charset = "iso-8859-1";
     $mail = new Zend_Mail($charset);
     $setReturnPath = Mage::getStoreConfig('system/smtp/set_return_path');
     switch ($setReturnPath) {
         case 1:
             $returnPathEmail = $this->getDestination()->getEmailSender();
             break;
         case 2:
             $returnPathEmail = Mage::getStoreConfig('system/smtp/return_path_email');
             break;
         default:
             $returnPathEmail = null;
             break;
     }
     if ($returnPathEmail !== null) {
         $mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $returnPathEmail);
         Zend_Mail::setDefaultTransport($mailTransport);
     }
     $mail->setFrom($this->getDestination()->getEmailSender(), $this->getDestination()->getEmailSender());
     foreach (explode(",", $this->getDestination()->getEmailRecipient()) as $email) {
         if ($charset === "utf-8") {
             $mail->addTo($email, '=?utf-8?B?' . base64_encode($email) . '?=');
         } else {
             $mail->addTo($email, $email);
         }
     }
     foreach ($fileArray as $filename => $data) {
         if ($this->getDestination()->getEmailAttachFiles()) {
             $attachment = $mail->createAttachment($data);
             $attachment->filename = $filename;
         }
         $savedFiles[] = $filename;
     }
     #$mail->setSubject($this->_replaceVariables($this->getDestination()->getEmailSubject(), $firstFileContent));
     if ($charset === "utf-8") {
         $mail->setSubject('=?utf-8?B?' . base64_encode($this->_replaceVariables($this->getDestination()->getEmailSubject(), implode("\n\n", $fileArray))) . '?=');
     } else {
         $mail->setSubject($this->_replaceVariables($this->getDestination()->getEmailSubject(), implode("\n\n", $fileArray)));
     }
     $mail->setBodyText(strip_tags($this->_replaceVariables($this->getDestination()->getEmailBody(), implode("\n\n", $fileArray))));
     $mail->setBodyHtml($this->_replaceVariables($this->getDestination()->getEmailBody(), implode("\n\n", $fileArray)));
     try {
         $mail->send(Mage::helper('xtcore/utils')->getEmailTransport());
     } catch (Exception $e) {
         $this->getTestResult()->setSuccess(false)->setMessage(Mage::helper('xtento_orderexport')->__('Error while sending email: %s', $e->getMessage()));
         return false;
     }
     return $savedFiles;
 }
Exemple #17
0
 public static function instance()
 {
     $args = func_get_args();
     $userOptions = array();
     if (count($args) > 0) {
         $userOptions = $args[0];
     }
     if (self::$_instance === null) {
         $options = array();
         if (isset(Bbx_Config::get()->site->smtp_username)) {
             $options = array('auth' => 'login', 'username' => Bbx_Config::get()->site->smtp_username, 'password' => Bbx_Config::get()->site->smtp_password);
         }
         if (isset(Bbx_Config::get()->site->smtp_port)) {
             $options['port'] = Bbx_Config::get()->site->smtp_port;
         }
         if (isset(Bbx_Config::get()->site->smtp_ssl)) {
             $options['ssl'] = Bbx_Config::get()->site->smtp_ssl;
         }
         $port = array_key_exists('port', $options) ? $options['port'] : 25;
         $options = array_merge($options, $userOptions);
         $transport = new Zend_Mail_Transport_Smtp(Bbx_Config::get()->site->smtp_server, $options);
         Zend_Mail::setDefaultTransport($transport);
         self::$_instance = new Bbx_Mail();
     }
     return self::$_instance;
 }
Exemple #18
0
 public function __construct($scriptName, $day = null)
 {
     if ($day != null) {
         $this->_day = $day;
     }
     $this->_scriptName = $scriptName;
     $this->_config = Zend_Registry::get('config');
     # init $this->_texts
     $this->_texts = new stdClass();
     $smtp_cfg = array('auth' => $this->_config->mail->auth, 'username' => $this->_config->mail->username, 'password' => $this->_config->mail->password);
     // echo 'auth: '. var_dump($this->_config->mail->auth);
     // echo 'username: '******'password: '******'auth' => 'login',
     //                 'username' => '*****@*****.**',
     //                 'password' => 'alexgemalexgem');
     $transport = new Zend_Mail_Transport_Smtp($this->_config->mail->smtp, $smtp_cfg);
     Zend_Mail::setDefaultTransport($transport);
     Zend_Mail::setDefaultFrom($this->_config->mail->addressFrom, $this->_config->mail->labelFrom);
     $langs = Zend_Registry::get('db')->fetchCol('SELECT DISTINCT(`lang`) FROM `user`');
     foreach ($langs as $lang) {
         $file = APPLICATION_PATH . '/configs/langs/' . $lang . '/emails.ini';
         $this->_texts->{$lang} = new Zend_Config_Ini($file, $this->_scriptName);
     }
 }
Exemple #19
0
 /**
  * @param string $subject
  *  The subject. May contain variable references to memebrs
  *  of the $fields array.
  * @param string $view
  *  The name of a view
  * @param array $fields
  *  The fields referenced in the subject and/or view
  * @param array $optoins
  *  Array of options. Can include:
  *  "html" => Defaults to false. Whether to send as HTML email.
  *  "name" => A human-readable name in addition to the address.
  *  "from" => An array of email_address => human_readable_name
  */
 function sendMessage($subject, $view, $fields = array(), $options = array())
 {
     if (!isset($options['from'])) {
         $url_parts = parse_url(Pie_Request::baseUrl());
         $domain = $url_parts['host'];
         $options['from'] = array("email_bot@" . $domain => $domain);
     } else {
         if (!is_array($options['from'])) {
             throw new Pie_Exception_WrongType(array('field' => '$options["from"]', 'type' => 'array'));
         }
     }
     // Set up the default mail transport
     $tr = new Zend_Mail_Transport_Sendmail('-f' . $this->address);
     Zend_Mail::setDefaultTransport($tr);
     $mail = new Zend_Mail();
     $from_name = reset($options['from']);
     $mail->setFrom(key($options['from']), $from_name);
     if (isset($options['name'])) {
         $mail->addTo($this->address, $options['name']);
     } else {
         $mail->addTo($this->address);
     }
     $subject = Pie::expandString($subject, $fields);
     $body = Pie::view($view, $fields);
     $mail->setSubject($subject);
     if (empty($options['html'])) {
         $mail->setBodyText($body);
     } else {
         $mail->setBodyHtml($body);
     }
     $mail->send();
     return true;
 }
Exemple #20
0
 protected function _initMail()
 {
     Zend_Mail::setDefaultFrom('*****@*****.**', 'XLR8U Fitness');
     Zend_Mail::setDefaultReplyTo('*****@*****.**', 'XLR8U Fitness');
     $transport = new Zend_Mail_Transport_Sendmail();
     Zend_Mail::setDefaultTransport($transport);
 }
Exemple #21
0
   /**
     * Constructor.
     *
     * @param  string $host OPTIONAL (Default: 127.0.0.1)
     * @param  array|null $config OPTIONAL (Default: null)
     * @return void
     */
    public function __construct( $method = 'mail', $charset = 'UTF-8' ) 
    {
        $this->_method              = $method;
        $this->_charset             = $charset;
		
        switch ( $this->_method ) {
            // Methode d'envoi par SMTP sécurisé TLS
            case 'smtp/tls' : 
                $this->_config      = array( 'auth' => 'login',
                                             'username' => $this->_getConfig()->frontoffice->mailer->smtpUser,
                                             'password' => $this->_getConfig()->frontoffice->mailer->smtpPwd,
                                             'ssl' => 'tls',
                                             'port' => $this->_getConfig()->frontoffice->mailer->smtpPort
                                            );
                $this->_transport   = new Zend_Mail_Transport_Smtp( $this->_getConfig()->frontoffice->mailer->smtpHost, $this->_config );
                Zend_Mail::setDefaultTransport( $this->_transport );
            break;
            // Méthode d'envoi par SMTP classique
            case 'smtp' :
                $this->_config      = array( 'port' => $this->_getConfig()->frontoffice->mailer->smtpPort );
                $this->_transport   = new Zend_Mail_Transport_Smtp( $this->_getConfig()->frontoffice->mailer->smtpHost, $this->_config );
                Zend_Mail::setDefaultTransport( $this->_transport );
            break;
            // Méthode d'envoi par fonction mail() ( fonctionnement par défaut)
            case 'mail' :
                // nothing 
            break;
            default :
                // nothing 
            break;
        }
        
    }
Exemple #22
0
 /**
  *  Send mail.
  *
  *  @access     public
  *  @param      object      $workload       Object with mail sender, receiver, subject and body
  *  @return     void
  *  @throws     InvalidArgumentException    if workload object has no sender
  *  @throws     InvalidArgumentException    if workload object has no receiver
  *  @throws     InvalidArgumentException    if workload object has no subject
  *  @throws     InvalidArgumentException    if workload object has no body
  */
 public function run($workload)
 {
     $smtpServer = $this->options['server'];
     $config = array();
     if ($this->options['auth']) {
         $config['auth'] = $this->options['auth'];
         $config['username'] = $this->options['username'];
         $config['password'] = $this->options['password'];
     }
     $transport = new Zend_Mail_Transport_Smtp($smtpServer, $config);
     if (is_object($workload)) {
         if (empty($workload->sender)) {
             throw new InvalidArgumentException('Workload is missing sender');
         }
         if (empty($workload->receiver)) {
             throw new InvalidArgumentException('Workload is missing receiver');
         }
         if (empty($workload->subject)) {
             throw new InvalidArgumentException('Workload is missing subject');
         }
         if (empty($workload->body)) {
             throw new InvalidArgumentException('Workload is missing body');
         }
         $mail = new Zend_Mail();
         $mail->setDefaultTransport($transport);
         $mail->addTo($workload->receiver);
         $mail->setSubject($workload->subject);
         $mail->setBodyText($workload->body);
         $mail->setFrom($workload->sender);
         $mail->send($transport);
         $this->logSuccess('Mail "' . $workload->subject . '" sent to ' . $workload->receiver);
     }
 }
Exemple #23
0
 /**
  * Send all messages in a queue
  *
  * @return Mage_Core_Model_Email_Queue
  */
 public function send()
 {
     /** @var $collection Mage_Core_Model_Resource_Email_Queue_Collection */
     $collection = Mage::getModel('core/email_queue')->getCollection()->addOnlyForSendingFilter()->setPageSize(self::MESSAGES_LIMIT_PER_CRON_RUN)->setCurPage(1)->load();
     ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
     ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
     /** @var $message Mage_Core_Model_Email_Queue */
     foreach ($collection as $message) {
         if ($message->getId()) {
             $parameters = new Varien_Object($message->getMessageParameters());
             if ($parameters->getReturnPathEmail() !== null) {
                 $mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $parameters->getReturnPathEmail());
                 Zend_Mail::setDefaultTransport($mailTransport);
             }
             $mailer = new Zend_Mail('utf-8');
             foreach ($message->getRecipients() as $recipient) {
                 list($email, $name, $type) = $recipient;
                 switch ($type) {
                     case self::EMAIL_TYPE_BCC:
                         $mailer->addBcc($email, '=?utf-8?B?' . base64_encode($name) . '?=');
                         break;
                     case self::EMAIL_TYPE_TO:
                     case self::EMAIL_TYPE_CC:
                     default:
                         $mailer->addTo($email, '=?utf-8?B?' . base64_encode($name) . '?=');
                         break;
                 }
             }
             if ($parameters->getIsPlain()) {
                 $mailer->setBodyText($message->getMessageBody());
             } else {
                 $mailer->setBodyHTML($message->getMessageBody());
             }
             $mailer->setSubject('=?utf-8?B?' . base64_encode($parameters->getSubject()) . '?=');
             $mailer->setFrom($parameters->getFromEmail(), $parameters->getFromName());
             if ($parameters->getReplyTo() !== null) {
                 $mailer->setReplyTo($parameters->getReplyTo());
             }
             if ($parameters->getReturnTo() !== null) {
                 $mailer->setReturnPath($parameters->getReturnTo());
             }
             try {
                 //$mailer->send();
                 $mailer->send(Mage::helper('smtp')->getTransport());
                 unset($mailer);
                 $message->setProcessedAt(Varien_Date::formatDate(true));
                 $message->save();
             } catch (Exception $e) {
                 unset($mailer);
                 $oldDevMode = Mage::getIsDeveloperMode();
                 Mage::setIsDeveloperMode(true);
                 Mage::logException($e);
                 Mage::setIsDeveloperMode($oldDevMode);
                 return false;
             }
         }
     }
     return $this;
 }
Exemple #24
0
 /**
  * Send mail to recipient
  *
  * @param array|string $email - E-mail(s)
  * @param null $name - receiver name(s)
  * @param array $variables - template variables
  * @return boolean
  * @throws Exception
  * @throws Zend_Mail_Exception
  */
 public function send($email, $name = null, array $variables = array())
 {
     /** @var Newsman_Newsletter_Helper_Smtp $_helper */
     $_helper = Mage::helper('newsman_newsletter/smtp');
     if (!$_helper->isEnabled()) {
         return parent::send($email, $name, $variables);
     }
     if (!$this->isValidForSend()) {
         Mage::logException(new Exception('This letter cannot be sent.'));
         // translation is intentionally omitted
         return false;
     }
     $emails = array_values((array) $email);
     $names = is_array($name) ? $name : (array) $name;
     $names = array_values($names);
     foreach ($emails as $key => $email) {
         if (!isset($names[$key])) {
             $names[$key] = substr($email, 0, strpos($email, '@'));
         }
     }
     $variables['email'] = reset($emails);
     $variables['name'] = reset($names);
     $this->setUseAbsoluteLinks(true);
     $text = $this->getProcessedTemplate($variables, true);
     $subject = $this->getProcessedTemplateSubject($variables);
     if ($this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) {
         /** @var $emailQueue Mage_Core_Model_Email_Queue */
         $emailQueue = $this->getQueue();
         $emailQueue->setMessageBody($text);
         $emailQueue->setMessageParameters(array('subject' => $subject, 'is_plain' => $this->isPlain(), 'from_email' => $this->getSenderEmail(), 'from_name' => $this->getSenderName(), 'reply_to' => $this->getMail()->getReplyTo(), 'return_to' => $this->getMail()->getReturnPath()))->addRecipients($emails, $names, Mage_Core_Model_Email_Queue::EMAIL_TYPE_TO)->addRecipients($this->_bccEmails, array(), Mage_Core_Model_Email_Queue::EMAIL_TYPE_BCC);
         $emailQueue->addMessageToQueue();
         return true;
     }
     ini_set('SMTP', $_helper->getHost());
     ini_set('smtp_port', $_helper->getPort());
     $mail = $this->getMail();
     $config = array('ssl' => $_helper->getSslType(), 'port' => $_helper->getPort(), 'auth' => $_helper->getAuth(), 'username' => $_helper->getUsername(), 'password' => $_helper->getPassword());
     $mailTransport = new Zend_Mail_Transport_Smtp($_helper->getHost(), $config);
     Zend_Mail::setDefaultTransport($mailTransport);
     foreach ($emails as $key => $email) {
         $mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?=');
     }
     if ($this->isPlain()) {
         $mail->setBodyText($text);
     } else {
         $mail->setBodyHTML($text);
     }
     $mail->setSubject('=?utf-8?B?' . base64_encode($subject) . '?=');
     $mail->setFrom($this->getSenderEmail(), $this->getSenderName());
     try {
         $mail->send();
         $this->_mail = null;
     } catch (Exception $e) {
         $this->_mail = null;
         Mage::logException($e);
         return false;
     }
     return true;
 }
Exemple #25
0
 protected function _initDefaultEmailTransport()
 {
     $emailConfig = $this->getOption('email');
     $smtpHost = $emailConfig['transportOptionsSmtp']['host'];
     unset($smtpHost);
     $mailTransport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $emailConfig['transportOptionsSmtp']);
     Zend_Mail::setDefaultTransport($mailTransport);
 }
Exemple #26
0
 protected function _setTransport()
 {
     if ($this->_mailTransport === null) {
         $config = array('auth' => 'login', 'username' => '*****@*****.**', 'password' => 'password (not really)', 'ssl' => 'tls', 'port' => 587);
         $this->_mailTransport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
         Zend_Mail::setDefaultTransport($this->_mailTransport);
     }
 }
Exemple #27
0
 protected function tearDown()
 {
     // restore static vars
     if ($this->_oldTransport !== null) {
         Zend_Mail::setDefaultTransport($this->_oldTransport);
     }
     Zend_Mail::setDefaultFrom($this->_oldFrom['email'], $this->_oldFrom['name']);
 }
 protected function _initEmailTransport()
 {
     $aConfig = $this->getOptions();
     $emailConfig = array('auth' => 'login', 'username' => $aConfig['email']['username'], 'password' => $aConfig['email']['password'], 'port' => $aConfig['email']['port']);
     $server = $aConfig['email']['server'];
     $transport = new Zend_Mail_Transport_Smtp($server, $emailConfig);
     Zend_Mail::setDefaultTransport($transport);
 }
 function send()
 {
     $this->save();
     // save
     $SET = G()->SET['qg']['mail'];
     require_once sysPATH . 'Zend/Mail.php';
     if (G()->SET['qg']['mail']['smtp']['host']->v) {
         require_once sysPATH . 'Zend/Mail/Transport/Smtp.php';
         $config = array('ssl' => 'tls');
         if ($SET['smtp']['port']->v) {
             $config['port'] = $SET['smtp']['port']->v;
         }
         if ($SET['smtp']['username']->v) {
             $config['auth'] = 'login';
             $config['username'] = $SET['smtp']['username']->v;
             $config['password'] = $SET['smtp']['password']->v;
         }
         $tr = new \Zend_Mail_Transport_Smtp($SET['smtp']['host']->v, $config);
     } else {
         require_once sysPATH . 'Zend/Mail/Transport/Sendmail.php';
         $tr = new \Zend_Mail_Transport_Sendmail('-f' . $SET['replay']->v);
     }
     \Zend_Mail::setDefaultTransport($tr);
     $toWebmaster = debug ? $SET['on debugmode to']->v : false;
     foreach (D()->mail_recipient->selectEntries("WHERE mail_id = " . $this . " AND sent = 0") as $Item) {
         $ZendMail = new \Zend_Mail('utf-8');
         $ZendMail->setFrom($this->sender, $this->sendername ? $this->sendername : $this->sender);
         $ZendMail->setSubject(($toWebmaster ? 'Debug! ' : '') . $this->subject);
         $html = $this->getHtml($Item, $ZendMail);
         // dirty hack for thunderbird, it needs multipart/related for inline-images
         if (strpos($html, 'cid:') !== false) {
             $ZendMail->setType(Zend_Mime::MULTIPART_RELATED);
             // ok?
         }
         $ZendMail->setBodyHtml(($toWebmaster ? 'original receiver :' . $Item->email . '<br><br>' : '') . $html);
         $ZendMail->setBodyText(($toWebmaster ? 'original receiver :' . $Item->email . "\n\n" : '') . $this->getText($Item, $ZendMail));
         $ZendMail->addTo($toWebmaster ? $toWebmaster : $Item->email, $Item->name);
         foreach (D()->query("SELECT * FROM mail_attachment WHERE mail_id = " . $this->id) as $vs) {
             $At = $ZendMail->createAttachment(file_get_contents($vs['path']));
             $At->filename = $vs['name'] ? $vs['name'] : basename($vs['path']);
             $At->type = $vs['type'] ? $vs['type'] : File::extensionToMime(preg_replace('/.*\\.([^.]+$)/', '$1', $vs['path']));
             $At->disposition = $vs['inline'] ? Zend_Mime::DISPOSITION_INLINE : Zend_Mime::DISPOSITION_ATTACHMENT;
             $At->id = $vs['hash'];
         }
         $sent = false;
         try {
             $sent = $ZendMail->send();
         } catch (Exception $e) {
             var_dump($this->sender);
             trigger_error('mail sending failed :' . $e);
         }
         if ($sent) {
             $Item->sent = time();
             $Item->save();
             // save
         }
     }
 }
Exemple #30
0
 /**
  * Send mail to recipient
  *
  * @param   array|string       $email        E-mail(s)
  * @param   array|string|null  $name         receiver name(s)
  * @param   array              $variables    template variables
  * @return  boolean
  **/
 public function send($email, $name = null, array $variables = array())
 {
     if (!$this->isValidForSend()) {
         Mage::logException(new Exception('This letter cannot be sent.'));
         // translation is intentionally omitted
         return false;
     }
     $emails = array_values((array) $email);
     $names = is_array($name) ? $name : (array) $name;
     $names = array_values($names);
     foreach ($emails as $key => $email) {
         if (!isset($names[$key])) {
             $names[$key] = substr($email, 0, strpos($email, '@'));
         }
     }
     $variables['email'] = reset($emails);
     $variables['name'] = reset($names);
     ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
     ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
     $mail = $this->getMail();
     $setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH);
     switch ($setReturnPath) {
         case 1:
             $returnPathEmail = $this->getSenderEmail();
             break;
         case 2:
             $returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL);
             break;
         default:
             $returnPathEmail = null;
             break;
     }
     if ($returnPathEmail !== null) {
         $mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $returnPathEmail);
         Zend_Mail::setDefaultTransport($mailTransport);
     }
     foreach ($emails as $key => $email) {
         $mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?=');
     }
     $this->setUseAbsoluteLinks(true);
     $text = $this->getProcessedTemplate($variables, true);
     if ($this->isPlain()) {
         $mail->setBodyText($text);
     } else {
         $mail->setBodyHTML($text);
     }
     $mail->setSubject('=?utf-8?B?' . base64_encode($this->getProcessedTemplateSubject($variables)) . '?=');
     $mail->setFrom($this->getSenderEmail(), $this->getSenderName());
     try {
         $mail->send(Mage::helper('logmail')->getMailTransport());
         $this->_mail = null;
     } catch (Exception $e) {
         $this->_mail = null;
         Mage::logException($e);
         return false;
     }
     return true;
 }