Skip to content

Instantly share code, notes, and snippets.

@hadl
Created April 16, 2014 09:48
Show Gist options
  • Save hadl/10843556 to your computer and use it in GitHub Desktop.
Save hadl/10843556 to your computer and use it in GitHub Desktop.
Magento: Fix Sendfriend Mail Sender. You can't send mails from your server with eg. gmail.com as sender mail address!
<?php
/**
* Mds_MagentoExtender_Model_Sendfriend_Sendfriend for our extension. Use your own name.
*/
class Mds_MagentoExtender_Model_Sendfriend_Sendfriend extends Mage_Sendfriend_Model_Sendfriend {
public function send()
{
if ($this->isExceedLimit()){
Mage::throwException(Mage::helper('sendfriend')->__('You have exceeded limit of %d sends in an hour', $this->getMaxSendsToFriend()));
}
/* @var $translate Mage_Core_Model_Translate */
$translate = Mage::getSingleton('core/translate');
$translate->setTranslateInline(false);
/* @var $mailTemplate Mage_Core_Model_Email_Template */
$mailTemplate = Mage::getModel('core/email_template');
$message = nl2br(htmlspecialchars($this->getSender()->getMessage()));
/*$sender = array(
'name' => $this->_getHelper()->escapeHtml($this->getSender()->getName()),
'email' => $this->_getHelper()->escapeHtml($this->getSender()->getEmail())
);*/
$sender = 'general';
$mailTemplate->setDesignConfig(array(
'area' => 'frontend',
'store' => Mage::app()->getStore()->getId()
));
foreach ($this->getRecipients()->getEmails() as $k => $email) {
$name = $this->getRecipients()->getNames($k);
$mailTemplate
->setReplyTo($this->_getHelper()->escapeHtml($this->getSender()->getEmail()))
->sendTransactional(
$this->getTemplate(),
$sender,
$email,
$name,
array(
'name' => $name,
'email' => $email,
'product_name' => $this->getProduct()->getName(),
'product_url' => $this->getProduct()->getUrlInStore(),
'message' => $message,
'sender_name' => $this->_getHelper()->escapeHtml($this->getSender()->getName()),
'sender_email' => $this->_getHelper()->escapeHtml($this->getSender()->getEmail()),
'product_image' => Mage::helper('catalog/image')->init($this->getProduct(),'small_image')->resize(75),
)
);
}
$translate->setTranslateInline(true);
$this->_incrementSentCount();
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment