Email template not working


#1

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://community.invoiceplane.com/t/topic/4419/3



#2

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.


#3

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


#4

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.


#5

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


#6

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


#7

@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


#8

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>

#9

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:


#10

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


#11

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.


#12

@oussamadouhou, did you try the fix I suggested?


#13

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.


#14

@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:

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.


#15

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


closed #16

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