Beispiel #1
0
 /**
  * Deleting subscriber from Mailchimp
  * @param AW_Advancednewsletter_Model_Subscriber $subscriber
  * @return AW_Advancednewsletter_Model_Sync_Mailchimp 
  */
 public function delete($subscriber)
 {
     $this->deleteOptional($subscriber->getEmail(), $subscriber->getStoreId());
     return $this;
 }
Beispiel #2
0
 /**
  * Send mail to subscriber
  *
  * @param   AW_Advancednewsletter_Model_Subscriber|string   $subscriber   subscriber Model or E-mail
  * @param   array                                           $variables    template variables
  * @param   string|null                                     $name         receiver name (if subscriber model not specified)
  * @param   AW_Advancednewsletter_Model_Queue|null          $queue        queue model
  * @return boolean
  **/
 public function send($subscriber, array $variables = array(), $name = null, Mage_Newsletter_Model_Queue $queue = null)
 {
     if (!$this->isValidForSend()) {
         return false;
     }
     $email = '';
     if ($subscriber instanceof AW_Advancednewsletter_Model_Subscriber) {
         $email = $subscriber->getEmail();
         $name = $subscriber->getFirstName() . ' ' . $subscriber->getLastName();
         $variables['awunsubscribe'] = '<a href="' . Mage::app()->getStore($subscriber->getStoreId())->getBaseUrl() . 'advancednewsletter/index/unsubscribeall/email/' . $subscriber->getEmail() . '">Unsubscribe</a>';
         $variables['awloginpage'] = '<a href="' . Mage::app()->getStore($subscriber->getStoreId())->getBaseUrl() . 'customer/account/login/">Manage subscriptions</a>';
     } else {
         $email = (string) $subscriber;
         $variables['awunsubscribe'] = '<a href="' . Mage::getBaseUrl() . '"advancednewsletter/index/unsubscribeall/email/' . $email . '">Unsubscribe</a>';
         $variables['awloginpage'] = '<a href="' . Mage::getBaseUrl() . 'customer/account/login/">Manage subscriptions</a>';
     }
     if (Mage::getStoreConfigFlag(Mage_Newsletter_Model_Subscriber::XML_PATH_SENDING_SET_RETURN_PATH)) {
         $this->getMail()->setReturnPath($this->getTemplateSenderEmail());
     }
     ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
     ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
     $mail = $this->getMail();
     $mail->addTo($email, $name);
     $text = $this->getProcessedTemplate($variables, true);
     if ($this->isPlain()) {
         $mail->setBodyText($text);
     } else {
         $mail->setBodyHTML($text);
     }
     try {
         $mail->setSubject($this->getProcessedTemplateSubject($variables));
         $mail->setFrom($this->getTemplateSenderEmail(), $this->getTemplateSenderName());
     } catch (Exception $ex) {
     }
     $smtp = Mage::getModel('advancednewsletter/smtp')->load($this->getSmtpId());
     $transport = null;
     if ($smtp->getId()) {
         if ($smtp->getUsessl()) {
             $config = array('ssl' => 'tls', 'port' => $smtp->getPort(), 'auth' => 'login', 'username' => $smtp->getUserName(), 'password' => $smtp->getPassword());
         } else {
             $config = array('port' => $smtp->getPort(), 'auth' => 'login', 'username' => $smtp->getUserName(), 'password' => $smtp->getPassword());
         }
         $transport = new Zend_Mail_Transport_Smtp($smtp->getServerName(), $config);
     }
     try {
         if ($transport) {
             $mail->send($transport);
         } else {
             $mail->send();
         }
         $this->_mail = null;
         if (!is_null($queue)) {
             $subscriber->received($queue);
         }
     } catch (Exception $e) {
         Mage::helper('awcore/logger')->log($this, $e->getMessage());
         return false;
     }
     return true;
 }