Getting HTML of transactional emails












5














I would like to know if it's possible to get code html of transactional emails before send email to user with template variables etc. I overrided _sendEmailTemplate and I try to get html code in this way:



protected function _sendEmailTemplate($template, $sender, $templateParams = array(), $storeId = null) {
/** @var $mailer Mage_Core_Model_Email_Template_Mailer */
$mailer = Mage::getModel('core/email_template_mailer');
$emailInfo = Mage::getModel('core/email_info');
$emailInfo->addTo($this->getEmail(), $this->getName());
$mailer->addEmailInfo($emailInfo);

// Set all required params and send emails
$mailer->setSender(Mage::getStoreConfig($sender, $storeId));
$mailer->setStoreId($storeId);
$mailer->setTemplateId(Mage::getStoreConfig($template, $storeId));
$mailer->setTemplateParams($templateParams);
$emailTemplate = Mage::getModel('core/email_template')->loadByCode($template); // I try to get template


$processedTemplate = $emailTemplate->getProcessedTemplate($templateParams); //set template variables and get html code
print_R($processedTemplate);
exit;
$mailer->send();
return $this;
}


Comments in code.
It doesn't work. Any ideas will be appreciated










share|improve this question
















bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • app/code/core/Mage/Core/Model/Email/Template.php Check send function there you can echo html of email and you can save it
    – Rohit Kundale
    Jan 13 '16 at 10:02


















5














I would like to know if it's possible to get code html of transactional emails before send email to user with template variables etc. I overrided _sendEmailTemplate and I try to get html code in this way:



protected function _sendEmailTemplate($template, $sender, $templateParams = array(), $storeId = null) {
/** @var $mailer Mage_Core_Model_Email_Template_Mailer */
$mailer = Mage::getModel('core/email_template_mailer');
$emailInfo = Mage::getModel('core/email_info');
$emailInfo->addTo($this->getEmail(), $this->getName());
$mailer->addEmailInfo($emailInfo);

// Set all required params and send emails
$mailer->setSender(Mage::getStoreConfig($sender, $storeId));
$mailer->setStoreId($storeId);
$mailer->setTemplateId(Mage::getStoreConfig($template, $storeId));
$mailer->setTemplateParams($templateParams);
$emailTemplate = Mage::getModel('core/email_template')->loadByCode($template); // I try to get template


$processedTemplate = $emailTemplate->getProcessedTemplate($templateParams); //set template variables and get html code
print_R($processedTemplate);
exit;
$mailer->send();
return $this;
}


Comments in code.
It doesn't work. Any ideas will be appreciated










share|improve this question
















bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • app/code/core/Mage/Core/Model/Email/Template.php Check send function there you can echo html of email and you can save it
    – Rohit Kundale
    Jan 13 '16 at 10:02
















5












5








5







I would like to know if it's possible to get code html of transactional emails before send email to user with template variables etc. I overrided _sendEmailTemplate and I try to get html code in this way:



protected function _sendEmailTemplate($template, $sender, $templateParams = array(), $storeId = null) {
/** @var $mailer Mage_Core_Model_Email_Template_Mailer */
$mailer = Mage::getModel('core/email_template_mailer');
$emailInfo = Mage::getModel('core/email_info');
$emailInfo->addTo($this->getEmail(), $this->getName());
$mailer->addEmailInfo($emailInfo);

// Set all required params and send emails
$mailer->setSender(Mage::getStoreConfig($sender, $storeId));
$mailer->setStoreId($storeId);
$mailer->setTemplateId(Mage::getStoreConfig($template, $storeId));
$mailer->setTemplateParams($templateParams);
$emailTemplate = Mage::getModel('core/email_template')->loadByCode($template); // I try to get template


$processedTemplate = $emailTemplate->getProcessedTemplate($templateParams); //set template variables and get html code
print_R($processedTemplate);
exit;
$mailer->send();
return $this;
}


Comments in code.
It doesn't work. Any ideas will be appreciated










share|improve this question















I would like to know if it's possible to get code html of transactional emails before send email to user with template variables etc. I overrided _sendEmailTemplate and I try to get html code in this way:



protected function _sendEmailTemplate($template, $sender, $templateParams = array(), $storeId = null) {
/** @var $mailer Mage_Core_Model_Email_Template_Mailer */
$mailer = Mage::getModel('core/email_template_mailer');
$emailInfo = Mage::getModel('core/email_info');
$emailInfo->addTo($this->getEmail(), $this->getName());
$mailer->addEmailInfo($emailInfo);

// Set all required params and send emails
$mailer->setSender(Mage::getStoreConfig($sender, $storeId));
$mailer->setStoreId($storeId);
$mailer->setTemplateId(Mage::getStoreConfig($template, $storeId));
$mailer->setTemplateParams($templateParams);
$emailTemplate = Mage::getModel('core/email_template')->loadByCode($template); // I try to get template


$processedTemplate = $emailTemplate->getProcessedTemplate($templateParams); //set template variables and get html code
print_R($processedTemplate);
exit;
$mailer->send();
return $this;
}


Comments in code.
It doesn't work. Any ideas will be appreciated







magento-1.9 email html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 2 '18 at 23:05









sv3n

9,65062352




9,65062352










asked Jan 13 '16 at 9:57









coreycorey

416




416





bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • app/code/core/Mage/Core/Model/Email/Template.php Check send function there you can echo html of email and you can save it
    – Rohit Kundale
    Jan 13 '16 at 10:02




















  • app/code/core/Mage/Core/Model/Email/Template.php Check send function there you can echo html of email and you can save it
    – Rohit Kundale
    Jan 13 '16 at 10:02


















app/code/core/Mage/Core/Model/Email/Template.php Check send function there you can echo html of email and you can save it
– Rohit Kundale
Jan 13 '16 at 10:02






app/code/core/Mage/Core/Model/Email/Template.php Check send function there you can echo html of email and you can save it
– Rohit Kundale
Jan 13 '16 at 10:02












1 Answer
1






active

oldest

votes


















0














It depends on what you want to do with the HTML code, but what I used to do to debug emails is log the email HTML code into a file.



Instead of using print_r, you can do:



Mage::log($processedTemplate, null, sprintf("email_%s.html", date("Ymd-his")));





share|improve this answer





















  • I want to save content of all HTML code in file on my harddisk for example :)
    – corey
    Jan 13 '16 at 10:02










  • The $processedTemplate variable contains the HTML of the email, from that point you can do whatever you want with it, just ensure your email is still being sent after you wrote your code.
    – Raphael at Digital Pianism
    Jan 13 '16 at 10:12










  • However I execute your Mage::log after send email, I can't get properly my HTML code, I don't know why because I check new email_2016-0113-101610.html and it's doesn't contain nothing instead of DEBUG and it's all. I don't get HTML code.
    – corey
    Jan 13 '16 at 10:18










  • Ok, I got it. It was simple: $mailer->getProcessedTemplate($templateVariables) instead of create new variable $emailTemplate
    – corey
    Jan 13 '16 at 10:26













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f97003%2fgetting-html-of-transactional-emails%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














It depends on what you want to do with the HTML code, but what I used to do to debug emails is log the email HTML code into a file.



Instead of using print_r, you can do:



Mage::log($processedTemplate, null, sprintf("email_%s.html", date("Ymd-his")));





share|improve this answer





















  • I want to save content of all HTML code in file on my harddisk for example :)
    – corey
    Jan 13 '16 at 10:02










  • The $processedTemplate variable contains the HTML of the email, from that point you can do whatever you want with it, just ensure your email is still being sent after you wrote your code.
    – Raphael at Digital Pianism
    Jan 13 '16 at 10:12










  • However I execute your Mage::log after send email, I can't get properly my HTML code, I don't know why because I check new email_2016-0113-101610.html and it's doesn't contain nothing instead of DEBUG and it's all. I don't get HTML code.
    – corey
    Jan 13 '16 at 10:18










  • Ok, I got it. It was simple: $mailer->getProcessedTemplate($templateVariables) instead of create new variable $emailTemplate
    – corey
    Jan 13 '16 at 10:26


















0














It depends on what you want to do with the HTML code, but what I used to do to debug emails is log the email HTML code into a file.



Instead of using print_r, you can do:



Mage::log($processedTemplate, null, sprintf("email_%s.html", date("Ymd-his")));





share|improve this answer





















  • I want to save content of all HTML code in file on my harddisk for example :)
    – corey
    Jan 13 '16 at 10:02










  • The $processedTemplate variable contains the HTML of the email, from that point you can do whatever you want with it, just ensure your email is still being sent after you wrote your code.
    – Raphael at Digital Pianism
    Jan 13 '16 at 10:12










  • However I execute your Mage::log after send email, I can't get properly my HTML code, I don't know why because I check new email_2016-0113-101610.html and it's doesn't contain nothing instead of DEBUG and it's all. I don't get HTML code.
    – corey
    Jan 13 '16 at 10:18










  • Ok, I got it. It was simple: $mailer->getProcessedTemplate($templateVariables) instead of create new variable $emailTemplate
    – corey
    Jan 13 '16 at 10:26
















0












0








0






It depends on what you want to do with the HTML code, but what I used to do to debug emails is log the email HTML code into a file.



Instead of using print_r, you can do:



Mage::log($processedTemplate, null, sprintf("email_%s.html", date("Ymd-his")));





share|improve this answer












It depends on what you want to do with the HTML code, but what I used to do to debug emails is log the email HTML code into a file.



Instead of using print_r, you can do:



Mage::log($processedTemplate, null, sprintf("email_%s.html", date("Ymd-his")));






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 13 '16 at 10:01









Raphael at Digital PianismRaphael at Digital Pianism

53.3k19111269




53.3k19111269












  • I want to save content of all HTML code in file on my harddisk for example :)
    – corey
    Jan 13 '16 at 10:02










  • The $processedTemplate variable contains the HTML of the email, from that point you can do whatever you want with it, just ensure your email is still being sent after you wrote your code.
    – Raphael at Digital Pianism
    Jan 13 '16 at 10:12










  • However I execute your Mage::log after send email, I can't get properly my HTML code, I don't know why because I check new email_2016-0113-101610.html and it's doesn't contain nothing instead of DEBUG and it's all. I don't get HTML code.
    – corey
    Jan 13 '16 at 10:18










  • Ok, I got it. It was simple: $mailer->getProcessedTemplate($templateVariables) instead of create new variable $emailTemplate
    – corey
    Jan 13 '16 at 10:26




















  • I want to save content of all HTML code in file on my harddisk for example :)
    – corey
    Jan 13 '16 at 10:02










  • The $processedTemplate variable contains the HTML of the email, from that point you can do whatever you want with it, just ensure your email is still being sent after you wrote your code.
    – Raphael at Digital Pianism
    Jan 13 '16 at 10:12










  • However I execute your Mage::log after send email, I can't get properly my HTML code, I don't know why because I check new email_2016-0113-101610.html and it's doesn't contain nothing instead of DEBUG and it's all. I don't get HTML code.
    – corey
    Jan 13 '16 at 10:18










  • Ok, I got it. It was simple: $mailer->getProcessedTemplate($templateVariables) instead of create new variable $emailTemplate
    – corey
    Jan 13 '16 at 10:26


















I want to save content of all HTML code in file on my harddisk for example :)
– corey
Jan 13 '16 at 10:02




I want to save content of all HTML code in file on my harddisk for example :)
– corey
Jan 13 '16 at 10:02












The $processedTemplate variable contains the HTML of the email, from that point you can do whatever you want with it, just ensure your email is still being sent after you wrote your code.
– Raphael at Digital Pianism
Jan 13 '16 at 10:12




The $processedTemplate variable contains the HTML of the email, from that point you can do whatever you want with it, just ensure your email is still being sent after you wrote your code.
– Raphael at Digital Pianism
Jan 13 '16 at 10:12












However I execute your Mage::log after send email, I can't get properly my HTML code, I don't know why because I check new email_2016-0113-101610.html and it's doesn't contain nothing instead of DEBUG and it's all. I don't get HTML code.
– corey
Jan 13 '16 at 10:18




However I execute your Mage::log after send email, I can't get properly my HTML code, I don't know why because I check new email_2016-0113-101610.html and it's doesn't contain nothing instead of DEBUG and it's all. I don't get HTML code.
– corey
Jan 13 '16 at 10:18












Ok, I got it. It was simple: $mailer->getProcessedTemplate($templateVariables) instead of create new variable $emailTemplate
– corey
Jan 13 '16 at 10:26






Ok, I got it. It was simple: $mailer->getProcessedTemplate($templateVariables) instead of create new variable $emailTemplate
– corey
Jan 13 '16 at 10:26




















draft saved

draft discarded




















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f97003%2fgetting-html-of-transactional-emails%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

An IMO inspired problem

Management

Has there ever been an instance of an active nuclear power plant within or near a war zone?