Jump to content

New image in e-mail tpl file


Andrejkov

Recommended Posts

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

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

  • Like 1
Link to comment
Share on other sites

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 by 4you.software (see edit history)
Link to comment
Share on other sites

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

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 by Andrejkov (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...