Andrejkov Posted October 27, 2022 Share Posted October 27, 2022 Hello, I have question, how I can add additional images to the e-mail template that will be attached to the message, as is the case with the store logo. <img height ="auto" src="{shop_logo}" width="100%" border= "0"> Where and how I an create a variable analogous to {shop_logo} so that it directs e.g. to the folder /img/n/filename. Currently I have added graphics with regular URL but it causes blockages in mail clients. I have store on PS. 1.7.7.4 Regards. Link to comment Share on other sites More sharing options...
ps8modules Posted October 27, 2022 Share Posted October 27, 2022 ./classes/Mail.php find: and change logo path. E.g.: Link to comment Share on other sites More sharing options...
Andrejkov Posted October 27, 2022 Author Share Posted October 27, 2022 1 hour ago, 4you.software said: ./classes/Mail.php find: and change logo path. E.g.: Hi, thank you but i dont want to change logo file. I need to create new variable with other file. Eq {newgraph}. Link to comment Share on other sites More sharing options...
ps8modules Posted October 27, 2022 Share Posted October 27, 2022 $templateVars[{'newgraph'}] = path Link to comment Share on other sites More sharing options...
Knowband Plugins Posted October 27, 2022 Share Posted October 27, 2022 You just need to pass the variable from the PHP, where the Mail::Send() funtion is called and use the same variable in the mail.html file. Suppose for Order confirmation mail, just pass the variable in the PaymentModule.php file, before the Mail::Send( (int) $order->id_lang, 'order_conf', $this->context->getTranslator()->trans( 'Order confirmation', [], 'Emails.Subject', $orderLanguage->locale ), $data, $this->context->customer->email, $this->context->customer->firstname . ' ' . $this->context->customer->lastname, null, null, $file_attachement, null, _PS_MAIL_DIR_, false, (int) $order->id_shop ); And use the same in order_conf.html 1 Link to comment Share on other sites More sharing options...
ps8modules Posted October 27, 2022 Share Posted October 27, 2022 (edited) Just that editing Mail.php is the right place, or use hooks in your module and add custom variable sending the email. public function hookActionEmailSendBefore($param) { /* set default or if not exists */ $newgraph = _PS_IMG_DIR_.'n/custom-image.jpg'; /* add image for specific template */ $mailTemplates = array('order_conf', 'my_custom_template'); $tpl_name = (string) $param['template']; $id_lang = (int) $param['id_lang']; /* if template in $mailTemplates */ if (in_array($tpl_name, $mailTemplates, true)) { if (file_exists($newgraph)) { $message = new Swift_Message(); $param['template_vars']['{newgraph}'] = $message->embed(\Swift_Image::fromPath($newgraph)); } } } Edited October 28, 2022 by 4you.software (see edit history) Link to comment Share on other sites More sharing options...
Andrejkov Posted October 31, 2022 Author Share Posted October 31, 2022 On 10/27/2022 at 7:39 PM, 4you.software said: Just that editing Mail.php is the right place, or use hooks in your module and add custom variable sending the email. public function hookActionEmailSendBefore($param) { /* set default or if not exists */ $newgraph = _PS_IMG_DIR_.'n/custom-image.jpg'; /* add image for specific template */ $mailTemplates = array('order_conf', 'my_custom_template'); $tpl_name = (string) $param['template']; $id_lang = (int) $param['id_lang']; /* if template in $mailTemplates */ if (in_array($tpl_name, $mailTemplates, true)) { if (file_exists($newgraph)) { $message = new Swift_Message(); $param['template_vars']['{newgraph}'] = $message->embed(\Swift_Image::fromPath($newgraph)); } } } I Add this code in modules/ps_emailsubscription/ps_emailsubscription.php but when I use <img height ="auto" src="{newgraph}" width="100%" border= "0"> in template i got empty e-mail message. My code is: public function hookActionEmailSendBefore($param) { /* set default or if not exists */ $newgraph = _PS_IMG_DIR_.'/mytestimg.png'; /* add image for specific template */ $mailTemplates = array('order_conf', 'newsletter_conf'); $tpl_name = (string) $param['template']; $id_lang = (int) $param['id_lang']; /* if template in $mailTemplates */ if (in_array($tpl_name, $mailTemplates, true)) { if (file_exists($newgraph)) { $message = new Swift_Message(); $param['template_vars']['{newgraph}'] = $message->embed(\Swift_Image::fromPath($newgraph)); } } } Link to comment Share on other sites More sharing options...
ps8modules Posted November 1, 2022 Share Posted November 1, 2022 Hi. Mail.php is a class and you cannot insert a hook into it like this. The code sample is for a custom module. 1 Link to comment Share on other sites More sharing options...
Andrejkov Posted November 1, 2022 Author Share Posted November 1, 2022 (edited) 4 hours ago, 4you.software said: Hi. Mail.php is a class and you cannot insert a hook into it like this. The code sample is for a custom module. Hi, I dont add this code to Mail.php. I add to module ps_emailsubscription in file ps_emailsubscription.php (I found there similar codes) So where i need to put this code in module emailsubscription?? Regards. Edited November 1, 2022 by Andrejkov (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now