Source for file Template.php

Documentation is available at Template.php

  1. <?php
  2.  
  3. /**
  4.  * This class wraps the Template email sending functionality
  5.  * If SMTP Pro is enabled it will send emails using the given
  6.  * configuration.
  7.  *
  8.  * @author Ashley Schroder (aschroder.com)
  9.  */
  10.  
  11.     
  12.     public function send($email$name=nullarray $variables array()) {
  13.         
  14.         // If it's not enabled, just return the parent result.
  15.         if (!Mage::helper('smtppro')->isEnabled()) {
  16.              return parent::send($email$name$variables);
  17.         
  18.  
  19.         Mage::log('SMTPPro is enabled, sending email in Aschroder_SMTPPro_Model_Email_Template');        
  20.        
  21.         
  22.         // The remainder of this function closely mirrors the parent
  23.         // method except for providing the SMTP auth details from the 
  24.         // configuration. This is not good OO, but the parent class 
  25.         // leaves little room for useful subclassing. This will probably 
  26.         // become redundant sooner or later anyway.         
  27.         
  28.         if(!$this->isValidForSend()) {
  29.             Mage::log('SMTPPro: Email not valid for sending - check template, and smtp enabled/disabled setting');        
  30.             Mage::logException(new Exception('This letter cannot be sent.'))// translation is intentionally omitted
  31.             return false;
  32.         }
  33.  
  34.         $emails array_values((array)$email);
  35.         $names is_array($name$name : (array)$name;
  36.         $names array_values($names);
  37.         foreach ($emails as $key => $email{
  38.             if (!isset($names[$key])) {
  39.                 $names[$keysubstr($email0strpos($email'@'));
  40.             }
  41.         }
  42.  
  43.         $variables['email'reset($emails);
  44.         $variables['name'reset($names);
  45.         
  46.         $mail $this->getMail();
  47.         
  48.            $dev Mage::helper('smtppro')->getDevelopmentMode();
  49.            
  50.         if ($dev == "contact"{
  51.             
  52.             $email Mage::getStoreConfig('contacts/email/recipient_email'$this->getDesignConfig()->getStore());
  53.             Mage::log("Development mode set to send all emails to contact form recipient: " $email);
  54.             
  55.         elseif ($dev == "supress"{
  56.             
  57.             Mage::log("Development mode set to supress all emails.");
  58.             # we bail out, but report success
  59.             return true;
  60.         }
  61.         
  62.         // In Magento core they set the Return-Path here, for the sendmail command.
  63.         // we assume our outbound SMTP server (or Gmail) will set that.
  64.         
  65.         foreach ($emails as $key => $email{
  66.             $mail->addTo($email'=?utf-8?B?' base64_encode($names[$key]'?=');
  67.         }
  68.         
  69.  
  70.         $this->setUseAbsoluteLinks(true);
  71.         $text $this->getProcessedTemplate($variablestrue);
  72.  
  73.         if($this->isPlain()) {
  74.             $mail->setBodyText($text);
  75.         else {
  76.             $mail->setBodyHTML($text);
  77.         }
  78.  
  79.         $mail->setSubject('=?utf-8?B?'.base64_encode($this->getProcessedTemplateSubject($variables)).'?=');
  80.         $mail->setFrom($this->getSenderEmail()$this->getSenderName());
  81.  
  82.         // If we are using store emails as reply-to's set the header
  83.         // Check the header is not already set by the application.
  84.         // The contact form, for example, set's it to the sender of 
  85.         // the contact. Thanks i960 for pointing this out.
  86.  
  87.         if (Mage::helper('smtppro')->isReplyToStoreEmail()
  88.             && !array_key_exists('Reply-To'$mail->getHeaders())) {
  89.  
  90.             // Patch for Zend upgrade
  91.             // Later versions of Zend have a method for this, and disallow direct header setting...
  92.             if (method_exists($mail"setReplyTo")) {
  93.                 $mail->setReplyTo($this->getSenderEmail()$this->getSenderName());
  94.             else {
  95.                 $mail->addHeader('Reply-To'$this->getSenderEmail());
  96.             }
  97.             Mage::log('ReplyToStoreEmail is enabled, just set Reply-To header: ' $this->getSenderEmail());
  98.                 
  99.         }
  100.  
  101.         $transport Mage::helper('smtppro')->getTransport($this->getDesignConfig()->getStore());
  102.         
  103.         try {
  104.             
  105.             Mage::log('About to send email');
  106.             $mail->send($transport)// Zend_Mail warning..
  107.             Mage::log('Finished sending email');
  108.             
  109.             // Record one email for each receipient
  110.              foreach ($emails as $key => $email{
  111.                 Mage::dispatchEvent('smtppro_email_after_send'
  112.                      array('to' => $email,
  113.                          'template' => $this->getTemplateId(),
  114.                          'subject' => $this->getProcessedTemplateSubject($variables),
  115.                          'html' => !$this->isPlain(),
  116.                          'email_body' => $text));
  117.                      
  118.             }
  119.             
  120.             $this->_mail null;
  121.         }
  122.         catch (Exception $e{
  123.             Mage::logException($e);
  124.             return false;
  125.         }
  126.  
  127.         return true;
  128.     }
  129. }

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