Source for file Template.php

Documentation is available at Template.php

  1. <?php
  2.  
  3. /**
  4.  * This class wraps the Newsletter email sending functionality
  5.  * 
  6.  * If SMTPPro is enabled it will send emails using the given
  7.  * configuration.
  8.  *
  9.  *
  10.  * @author Ashley Schroder (aschroder.com)
  11.  * @copyright  Copyright (c) 2010 Ashley Schroder
  12.  * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  13.  */
  14.  
  15.     
  16.     
  17.      /**
  18.      * Send mail to subscriber
  19.      *
  20.      * @param   Mage_Newsletter_Model_Subscriber|string  $subscriber   subscriber Model or E-mail
  21.      * @param   array                                     $variables    template variables
  22.      * @param   string|null                              $name         receiver name (if subscriber model not specified)
  23.      * @param   Mage_Newsletter_Model_Queue|null         $queue        queue model, used for problems reporting.
  24.      * @return boolean 
  25.      ***/
  26.     public function send($subscriberarray $variables array()$name=nullMage_Newsletter_Model_Queue $queue=null)
  27.     {
  28.         if(!$this->isValidForSend()) {
  29.             return false;
  30.         }
  31.         
  32.         // If it's not enabled, just return the parent result.
  33.         if (!Mage::helper('smtppro')->isEnabled()) {
  34.              return parent::send($subscriber$variables$name$queue);
  35.         
  36.  
  37.         Mage::log('SMTPPro is enabled, sending email in Aschroder_SMTPPro_Model_Newsletter_Template')
  38.         
  39.  
  40.         $email '';
  41.         if ($subscriber instanceof Mage_Newsletter_Model_Subscriber{
  42.             $email $subscriber->getSubscriberEmail();
  43.             if (is_null($name&& ($subscriber->hasCustomerFirstname(|| $subscriber->hasCustomerLastname()) ) {
  44.                 $name $subscriber->getCustomerFirstname(' ' $subscriber->getCustomerLastname();
  45.             }
  46.         else {
  47.             $email = (string) $subscriber;
  48.         }
  49.  
  50.         $mail $this->getMail();
  51.  
  52.         if (Mage::getStoreConfigFlag(Mage_Newsletter_Model_Subscriber::XML_PATH_SENDING_SET_RETURN_PATH)) {
  53.             // This is important for SPAM I think, what value should it be?
  54.             $mail->setReturnPath($this->getTemplateSenderEmail());
  55.         }
  56.  
  57.         $transport Mage::helper('smtppro')->getTransport();
  58.         
  59.         $dev Mage::helper('smtppro')->getDevelopmentMode();
  60.            
  61.         if ($dev == "contact"{
  62.             
  63.             $email Mage::getStoreConfig('contacts/email/recipient_email');
  64.             Mage::log("Development mode set to send all emails to contact form recipient: " $email);
  65.             
  66.         elseif ($dev == "supress"{
  67.             
  68.             Mage::log("Development mode set to supress all emails.");
  69.             # we bail out, but report success
  70.             return true;
  71.         }
  72.  
  73.         $mail->addTo($email$name);
  74.         $text $this->getProcessedTemplate($variablestrue);
  75.  
  76.         if($this->isPlain()) {
  77.             $mail->setBodyText($text);
  78.         else {
  79.             $mail->setBodyHTML($text);
  80.         }
  81.  
  82.         $mail->setSubject($this->getProcessedTemplateSubject($variables));
  83.         $mail->setFrom($this->getTemplateSenderEmail()$this->getTemplateSenderName());
  84.         
  85.          // If we are using store emails as reply-to's set the header
  86.         if (Mage::helper('smtppro')->isReplyToStoreEmail()) {
  87.             // Later versions of Zend have a method for this, and disallow direct header setting...
  88.             if (method_exists($mail"setReplyTo")) {
  89.                 $mail->setReplyTo($this->getTemplateSenderEmail()$this->getTemplateSenderName());
  90.             else {
  91.                 $mail->addHeader('Reply-To'$this->getTemplateSenderEmail());
  92.             }
  93.             Mage::log('ReplyToStoreEmail is enabled, just set Reply-To header: ' $this->getTemplateSenderEmail());
  94.         }
  95.  
  96.         try {
  97.             
  98.             Mage::log('About to send email');
  99.             $mail->send($transport);
  100.             Mage::log('Finished sending email');
  101.             
  102.              Mage::dispatchEvent('smtppro_email_after_send'
  103.                  array('to' => $email,
  104.                          'template' => $this->getTemplateId(),
  105.                          'subject' => $mail->getSubject(),
  106.                          'html' => !$this->isPlain(),
  107.                          'email_body' => $text));
  108.                 
  109.             
  110.             $this->_mail null;
  111.             if(!is_null($queue)) {
  112.                 $subscriber->received($queue);
  113.             }
  114.         }
  115.         catch (Exception $e{
  116.             if($subscriber instanceof Mage_Newsletter_Model_Subscriber{
  117.                 // If letter sent for subscriber, we create a problem report entry
  118.                 $problem Mage::getModel('newsletter/problem');
  119.                 $problem->addSubscriberData($subscriber);
  120.                 if(!is_null($queue)) {
  121.                     $problem->addQueueData($queue);
  122.                 }
  123.                 $problem->addErrorData($e);
  124.                 $problem->save();
  125.  
  126.                 if(!is_null($queue)) {
  127.                     $subscriber->received($queue);
  128.                 }
  129.             else {
  130.                 // Otherwise throw error to upper level
  131.                 throw $e;
  132.             }
  133.             return false;
  134.         }
  135.  
  136.         return true;
  137.     }
  138.     
  139. }

Documentation generated on Fri, 09 Oct 2015 03:37:11 +0200 by phpDocumentor 1.4.4