Email template not working

Hi everybody,

I know this problem has been discussed many times before, but i still face the issue that my email template is saved and stored in the database. But when i the click on send email button, on the next page the email body is empty.

com-video-to-gif%20(1)

To be clear i have already checked all the things discussed in the topics:
https://community2.invoiceplane.com/t/topic/4235
https://community2.invoiceplane.com/t/topic/4419/3
https://community2.invoiceplane.com/t/topic/1729/14
https://community2.invoiceplane.com/t/topic/3988
https://community2.invoiceplane.com/t/email-templates-not-working-after-upgrade/1500

If you are open to it, send me the template info via PM. I will try it on my own dev system to see if the I can replicate this.

1 Like

Sure, we are an opensource community after all.

Thanks for the help in advanced @crafter

Hereby the link to the HTML template:
https://office.glasherstelzeist.nl/mail.html

Yea I forgot about this been busy :frowning: But i can confirm it.

I can’t seem to get it working either. but had not had time to investigate…
Plus i was unsure if i was doing something wrong wanted to check documentation.

Hi, mag hij in de… :grin: Right english, Can we add it to the template repository ? I can cut the logo’s if wished.

Sure, like I said, we are an opensource community after all :wink:

1 Like

@oussamadouhou I haven’t looked at your html source yet but make sure it’s as clean as possible. No microsoft word html in there.

Also don’t paste all the html in your email template. Do it step by step and make sure the template works after each pice that you pasted.

Right now InvoicePlane is confused about the html that you pasted

I have a possible fix. Do you have development experience. If so you can apply the fix. Otherwise we will have to submit this as a bug and go through the development process.

The fix is to applied in the file : application/modules/mailer/views/invoice.php

The top of the file currently reads

<script>
    $(function () {
        var template_fields = ["body", "subject", "from_name", "from_email", "cc", "bcc", "pdf_template"];

        $('#email_template').change(function () {
            var email_template_id = $(this).val();

            if (email_template_id === '') return;

            $.post("<?php echo site_url('email_templates/ajax/get_content'); ?>", {
                email_template_id: email_template_id
            }, function (data) {
                <?php echo(IP_DEBUG ? 'console.log(data);' : ''); ?>
                inject_email_template(template_fields, JSON.parse(data));
            });
        });

        var selected_email_template = <?php echo $email_template ?>;
        inject_email_template(template_fields, selected_email_template);
    });
</script>

The lines above must be changed as below (I added code on lines 14, 18 and 24 below)

<script>
    $(function () {
        var template_fields = ["body", "subject", "from_name", "from_email", "cc", "bcc", "pdf_template"];

        $('#email_template').change(function () {
            var email_template_id = $(this).val();

            if (email_template_id === '') return;

            $.post("<?php echo site_url('email_templates/ajax/get_content'); ?>", {
                email_template_id: email_template_id
            }, function (data) {

                $('.email-template-body').val(JSON.parse(data).email_template_body);
                <?php echo(IP_DEBUG ? 'console.log(data);' : ''); ?>
                inject_email_template(template_fields, JSON.parse(data));

                update_email_template_preview();
            });
        });

        var selected_email_template = <?php echo $email_template ?>;
        inject_email_template(template_fields, selected_email_template);
        update_email_template_preview();

    });
</script>

Hi @oussamadouhou,

Could you please check if the demo fits your need ?

What I figured out is that, on Web page Email Quote and Email Invoice, the Body textarea field will be filled with same filed of selected email template via js function inject_email_template.

I’m not sure if this is a bug or for a certain purpose, but the function inject_email_template uses jQuery html() method to fill html content that retrieve from site_url('email_templates/ajax/get_content') into Body teatarea field, and that causes some unexpected errors.

To fix the issue, you could try the steps as below:

  1. Use the unminified script. Edit file application/modules/layout/views/layout.php at line 46, change …assets/core/js/scripts.min.js to …assets/core/js/scripts.js.

  2. Replace html() method with val(). Edit file assets/core/js/scripts.js at line 50, change $("#" + key).html(val); to $("#" + key).val(val);.

Then it should work as the demo video :slight_smile:

2 Likes

Hi @wake,

Thank you for your quick respond. I did exactly what you said but still no luck.

Some extra data, the same html code i use for my invoice with different variables and that one works.

OffertesenFacturaties-GoogleChro

Hi @crafter,

It doesn’t seems to be a problem in de invoice script but in the quote.

Invoice is working like a champ, but in the quote it isn’t.

1 Like

@oussamadouhou, did you try the fix I suggested?

I will tomorrow crafter. I have some issue regarding my internet now :frowning: typing on my phone at the moment.

Tomorrow I will check if the issue remains after you fix crafter.

@oussamadouhou Thanks for your feedback. As your image shows, it seems the Body textarea still accepted email template as html code but not pure text, notice that the font size and line-height had been changed when option was selected.

I reproduce the situation as below to make it more clear:

https://dpr.wake.gs/cZTLlk

Could you please try it again with Chrome incognito mode to see if script.js is loaded correctly and not cached in browser ? Hope it doesn’t inconvenience you too much.

2 Likes

Hi @wake;

I did try it in the incognito browser but still an empty field. If i look into the source of the page the email is somehow loaded but not passthrough the text area.

** END OF TOPIC, PLEASE GO BACK TO THE SOLUTION OF @wake

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.