Source for file Template.php
Documentation is available at Template.php
* This class wraps the Template email sending functionality
* If SMTP Pro is enabled it will send emails using the given
* @author Ashley Schroder (aschroder.com)
public function send($email, $name=
null, array $variables =
array()) {
// If it's not enabled, just return the parent result.
if (!Mage::helper('smtppro')->isEnabled()) {
return parent::send($email, $name, $variables);
Mage::log('SMTPPro is enabled, sending email in Aschroder_SMTPPro_Model_Email_Template');
// The remainder of this function closely mirrors the parent
// method except for providing the SMTP auth details from the
// configuration. This is not good OO, but the parent class
// leaves little room for useful subclassing. This will probably
// become redundant sooner or later anyway.
if(!$this->isValidForSend()) {
Mage::log('SMTPPro: Email not valid for sending - check template, and smtp enabled/disabled setting');
Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted
$names =
is_array($name) ?
$name : (array)
$name;
foreach ($emails as $key =>
$email) {
if (!isset
($names[$key])) {
$variables['email'] =
reset($emails);
$variables['name'] =
reset($names);
$dev =
Mage::helper('smtppro')->getDevelopmentMode();
$email =
Mage::getStoreConfig('contacts/email/recipient_email', $this->getDesignConfig()->getStore());
Mage::log("Development mode set to send all emails to contact form recipient: " .
$email);
} elseif ($dev ==
"supress") {
Mage::log("Development mode set to supress all emails.");
# we bail out, but report success
// In Magento core they set the Return-Path here, for the sendmail command.
// we assume our outbound SMTP server (or Gmail) will set that.
foreach ($emails as $key =>
$email) {
$mail->addTo($email, '=?utf-8?B?' .
base64_encode($names[$key]) .
'?=');
$this->setUseAbsoluteLinks(true);
$text =
$this->getProcessedTemplate($variables, true);
$mail->setBodyText($text);
$mail->setBodyHTML($text);
$mail->setSubject('=?utf-8?B?'.
base64_encode($this->getProcessedTemplateSubject($variables)).
'?=');
$mail->setFrom($this->getSenderEmail(), $this->getSenderName());
// If we are using store emails as reply-to's set the header
// Check the header is not already set by the application.
// The contact form, for example, set's it to the sender of
// the contact. Thanks i960 for pointing this out.
if (Mage::helper('smtppro')->isReplyToStoreEmail()
// Patch for Zend upgrade
// Later versions of Zend have a method for this, and disallow direct header setting...
$mail->setReplyTo($this->getSenderEmail(), $this->getSenderName());
$mail->addHeader('Reply-To', $this->getSenderEmail());
Mage::log('ReplyToStoreEmail is enabled, just set Reply-To header: ' .
$this->getSenderEmail());
$transport =
Mage::helper('smtppro')->getTransport($this->getDesignConfig()->getStore());
Mage::log('About to send email');
$mail->send($transport); // Zend_Mail warning..
Mage::log('Finished sending email');
// Record one email for each receipient
foreach ($emails as $key =>
$email) {
Mage::dispatchEvent('smtppro_email_after_send',
'template' =>
$this->getTemplateId(),
'subject' =>
$this->getProcessedTemplateSubject($variables),
'html' =>
!$this->isPlain(),
Documentation generated on Fri, 09 Oct 2015 03:37:11 +0200 by phpDocumentor 1.4.4