Jump to content

[SOLVED - UPDATED 15/07/2015] Email templates url broken after editing (%7B, %7D) - Easy fix added!


Recommended Posts

  • 2 weeks later...

Thanks for this solution ;)

 

Fast two-liner solution if you are lazy and olso have linux shell access:

 

1. Copy /themes/THEME_DIR/mails/LANGUAGE_DIR/ to other localisation (for backup if sth goes wrong case).

2. Execute two lines:

 

for i in `ls |grep 'html'`; do echo "Repair: $i" && sed -i "s/%7B/{/g" $i && echo -ne " -DONE- \n"; done
for i in `ls |grep 'html'`; do echo "Repair: $i" && sed -i "s/%7D/}/g" $i && echo -ne " -DONE- \n"; done
 
Replace all %7B to { and %7D to } marks.
 
3. Copy with overriding current .html files.
Edited by efrenzy (see edit history)
  • Like 2

Share this post


Link to post
Share on other sites

I have created account especially to thank to Crezzur. I spent over 3 hours fighting with the issue and only thing I figured out was to to add redundant %7Bkeys%7D => values pairs to template_vars table.

 

Your investigation togheter with  sed -i "s/%7D/}/g" ./* in mails html templates diretory is much better.

 

Job done smoothly ! Take care

  • Like 1

Share this post


Link to post
Share on other sites

Hey all,

 

I noticed several people are having issue's when translating templates the url's become broken.

the brackets " { " and " } " are replaced by %7B and %7D.

 

After a small search i have found what the issue is.

I have added a patch for this and going to share it with you guys since it will take a while when there will come a new update for prestashop (i guess).

 

YOUR_WEBSITE_ROOT/controllers/admin/AdminTranslationsController.php

 

Search for:

file_put_contents($path.$mail_name.'.'.$type_content, Tools::purifyHTML($content));

Replace that line with:

file_put_contents($path.$mail_name.'.'.$type_content, $content);

Note: after adding this change you have to replace %7B and %7D. with " { " and " } " (Now they wont change anymore!)

 

Enjoy!

 

And like this post if it helped you so other people can find this fix.

 

Bugreport: http://forge.prestashop.com/browse/PSCSX-4594?jql=

 

 

i didnt have this problem on 1.6.0.9,its fixed for 1.6.0.13 ? do you know anything about it?

  • Like 1

Share this post


Link to post
Share on other sites

  • 1 month later...

I did that and it didn't fix my problem, Email links are still not working...can you help?

 

This fix works, did you replace all %7B to { and %7D to } marks.

example:

%7Bweburl%7D change to  {weburl}

 

post your page code here so i can thake a look if you did it right if it still doesnt work

Share this post


Link to post
Share on other sites

Hi Crezzur, 

where i can found this: YOUR_WEBSITE_ROOT/controllers/admin/AdminTranslationsController.php.

I have prestashop cloud with ftp account but by FileZilla i can't find these directory.

I have this problem in the emails...there are no shop's logo (it's as attached file) and the links in the email don't work.

Thanks for your help.

 

 

P.S. i tried to modify something in the email by my BO of prestashop and it delete me all EN folders about the emails.

Edited by lULYS (see edit history)

Share this post


Link to post
Share on other sites

This fix works, did you replace all %7B to { and %7D to } marks.

example:

%7Bweburl%7D change to  {weburl}

 

post your page code here so i can thake a look if you did it right if it still doesnt work

 

do I have to manually replace it on each email? because I didn't do that..

I have just updated the AdminTranslationsController.php file and have replaced classes/Tools.php files

 

my website is www.pandabanana.com.br

what do you need to access the code?

Share this post


Link to post
Share on other sites

do I have to manually replace it on each email? because I didn't do that..

I have just updated the AdminTranslationsController.php file and have replaced classes/Tools.php files

 

my website is www.pandabanana.com.br

what do you need to access the code?

yes or delete the translated files in your theme folder

Share this post


Link to post
Share on other sites

  • 3 weeks later...

When i send emails, i can't click on the links, so i don't think it's ok yet. :mellow:

 

1. Locate which e-mail is having the issue: (newsletter, order confirmed, account created, order send, ....)

2. Open the e-mail in your prestashop editor.

3. Edited the %7B with brackets (see image)

UfDdzMw.png

  • Like 1

Share this post


Link to post
Share on other sites

  • 3 weeks later...

Big tip for those who struggle to replace %7B and %7D with  brackets { } (respectively) in every email template:

download any freeware enchanced txt editor (I used Notepad++ for example),

go to ../themes/[TEMPLATE NAME]/mails/[the language folder in which links don't work]/   ,

download all html file templates to separate folder,

MAKE BACKUP OF IT!

select html file templates (CTRL + A?) and open with the txt editor

use "replace with..." function to replace "%7B" with "{" and then "%7D" with "}".

Save all files,

Upload edited files to the very same folder they were picked from.

 

 

all this process takes around 2-3 minutes to complete - fast, easy and most important - you will avoid missing some bracket somewhere.

  • Like 3

Share this post


Link to post
Share on other sites

Big tip for those who struggle to replace %7B and %7D with  brackets { } (respectively) in every email template:

download any freeware enchanced txt editor (I used Notepad++ for example),

go to ../themes/[TEMPLATE NAME]/mails/[the language folder in which links don't work]/   ,

download all html file templates to separate folder,

MAKE BACKUP OF IT!

select html file templates (CTRL + A?) and open with the txt editor

use "replace with..." function to replace "%7B" with "{" and then "%7D" with "}".

Save all files,

Upload edited files to the very same folder they were picked from.

 

 

all this process takes around 2-3 minutes to complete - fast, easy and most important - you will avoid missing some bracket somewhere.

 

Well explained ;)

Share this post


Link to post
Share on other sites

I'm not sure if anyone else encountered this, not only does it alter the "{" and "}" upon editing, but In my experience tonight, it also removed the style of the template.

 

My default mail themes had this style:

<style>	@media only screen and (max-width: 300px){ 
				body {
					width:218px !important;
					margin:auto !important;
				}
				.table {width:195px !important;margin:auto !important;}
				.logo, .titleblock, .linkbelow, .box, .footer, .space_footer{width:auto !important;display: block !important;}		
				span.title{font-size:20px !important;line-height: 23px !important}
				span.subtitle{font-size: 14px !important;line-height: 18px !important;padding-top:10px !important;display:block !important;}		
				td.box p{font-size: 12px !important;font-weight: bold !important;}
				.table-recap table, .table-recap thead, .table-recap tbody, .table-recap th, .table-recap td, .table-recap tr { 
					display: block !important; 
				}
				.table-recap{width: 200px!important;}
				.table-recap tr td, .conf_body td{text-align:center !important;}	
				.address{display: block !important;margin-bottom: 10px !important;}
				.space_address{display: none !important;}	
			}
	@media only screen and (min-width: 301px) and (max-width: 500px) { 
				body {width:308px!important;margin:auto!important;}
				.table {width:285px!important;margin:auto!important;}	
				.logo, .titleblock, .linkbelow, .box, .footer, .space_footer{width:auto!important;display: block!important;}	
				.table-recap table, .table-recap thead, .table-recap tbody, .table-recap th, .table-recap td, .table-recap tr { 
					display: block !important; 
				}
				.table-recap{width: 295px !important;}
				.table-recap tr td, .conf_body td{text-align:center !important;}
				
			}
	@media only screen and (min-width: 501px) and (max-width: 768px) {
				body {width:478px!important;margin:auto!important;}
				.table {width:450px!important;margin:auto!important;}	
				.logo, .titleblock, .linkbelow, .box, .footer, .space_footer{width:auto!important;display: block!important;}			
			}
	@media only screen and (max-device-width: 480px) { 
				body {width:308px!important;margin:auto!important;}
				.table {width:285px;margin:auto!important;}	
				.logo, .titleblock, .linkbelow, .box, .footer, .space_footer{width:auto!important;display: block!important;}
				
				.table-recap{width: 295px!important;}
				.table-recap tr td, .conf_body td{text-align:center!important;}	
				.address{display: block !important;margin-bottom: 10px !important;}
				.space_address{display: none !important;}	
			}
</style>

After BO editing, this style was removed.

 

At the moment, In my (Greenhorn) opinion, stay away from back office editing of Email templates, editing the actual files in Notepad++ will guarentee you get the result your looking for.

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Hi,

 

You are right. This might fix this for next release. https://github.com/PrestaShop/PrestaShop/pull/3061/files

 

Regards

 

Yeah already noticed the bug report is been marked als solved (http://forge.prestashop.com/browse/PSCSX-4594?jql=)

https://github.com/PrestaShop/PrestaShop/pull/2728/files

 

The fix is already implemented in 1.6.0.14 so the only version having this issue schould be 1.6.0.9

Hi friends, I'm having that problem again...

 

Using prestashop 1.6.0.11 the changes I make are simply not sticking... can anyone please help?

My links are still broken

It schould work the files cant change by it self as far as i know.

Share this post


Link to post
Share on other sites

 

Yeah already noticed the bug report is been marked als solved (http://forge.prestas...PSCSX-4594?jql=)

https://github.com/P...pull/2728/files

 

The fix is already implemented in 1.6.0.14 so the only version having this issue schould be 1.6.0.9

 

I've experienced broken url's and the style being removed on a fresh 1.6.0.14 install, so if it was fixed in 1.6.0.14, im at a loss.

Share this post


Link to post
Share on other sites

hey guys , i already figured out this problem. please go to /themes/default-bootstrap/mails/en and then replace all%7D and %7B to { }. and same in mail alert module. that is resolve. i was changing those codes to main mail folder. which i think many of us are replacing those codes to Mail folder which is not in the theme. if any question please post it . i can send you detail information

Share this post


Link to post
Share on other sites

Yeah already noticed the bug report is been marked als solved (http://forge.prestashop.com/browse/PSCSX-4594?jql=)

https://github.com/PrestaShop/PrestaShop/pull/2728/files

 

The fix is already implemented in 1.6.0.14 so the only version having this issue schould be 1.6.0.9

It schould work the files cant change by it self as far as i know.

 

Hi,
 
I replaced that line file_put_contents($path.$mail_name.'.'.$type_content, Tools::purifyHTML($content, array('{', '}')));
 
then I changed classes/Tools.php and controllers/admin/AdminTranslationsController.php files as they were saying here (https://github.com/PrestaShop/PrestaShop/pull/2728/files)
 
I'm unable to change the tools/htmlpurifier/HTMLPurifier.standalone.php file, every time I try to, my website goes offline.
 
With all previous changes I still can't make the url brackets to work, still don't know what is going on in that case. In my older prestashop install those changes worked for me... not it doesn't...
 
 
EDIT: I managed to change the tools/htmlpurifier/HTMLPurifier.standalone.php
 
and now things seem to work fine, thank you for your reply anyway! 
Edited by technico2006 (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

Hi,

 

All my links are broken too.

 

The first answer I saw was to replace the %7B and D by "{" and "}". I changed every mails (sooo long), but for nothing...

 

Then I made the change in the Translation Controller, but it still does not work, the %7 comes again and again.

 

 

The problem is the same with the logo (see attachement) : I don't see it, and the code is still wrong. 

 

I tried also to make the change in the core email templates.

 

 

Do you know what I'm missing ? Thanks a lot in advance !

 

ETA : I'm in 1.6.0.14

post-1003114-0-61364900-1432992116_thumb.jpg

Edited by malice animale (see edit history)

Share this post


Link to post
Share on other sites

 

Hi,
 
I replaced that line file_put_contents($path.$mail_name.'.'.$type_content, Tools::purifyHTML($content, array('{', '}')));
 
then I changed classes/Tools.php and controllers/admin/AdminTranslationsController.php files as they were saying here (https://github.com/PrestaShop/PrestaShop/pull/2728/files)
 
I'm unable to change the tools/htmlpurifier/HTMLPurifier.standalone.php file, every time I try to, my website goes offline.
 
With all previous changes I still can't make the url brackets to work, still don't know what is going on in that case. In my older prestashop install those changes worked for me... not it doesn't...
 
 
EDIT: I managed to change the tools/htmlpurifier/HTMLPurifier.standalone.php
 
and now things seem to work fine, thank you for your reply anyway! 

 

 

I missed the change proposed by technico2006, I made it, now it works ! I'm relieved :)

 

I just have to change (again !) all the %7B and %7D, but it seems it is the last time.

 

Thanks to the community help !

Share this post


Link to post
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Bonjour à tous et merci à Crezzur pour la résolution de ce petit problème.

 

Petite astuce pour modifier ensuite massivement tous les fichiers mails :

 

Avec Filezilla (ou autre logiciel ftp), télécharger tous les fichiers html du dossier /theme/mail/fr dans un dossier sur votre ordinateur

 

Avec Notepad+, faire CTRL+F et allez dans l'onglet "Rechercher dans les fichiers d'un dossier". Spécifiez le dossier où vous avez téléchargé les fichiers html et faites la recherche %7B à remplacer par { et cliquez sur "Remplacer tout".

Faites de même pour %7D par }

 

Tous les fichiers seront modifiés, il n'y a plus qu'à les remettre sur votre FTP. L'opération prends 30 sec. :)

  • Like 2

Share this post


Link to post
Share on other sites

Hi,

         This solution only works with Prestashop emails, not for Modules. Modules Emails is getting this error =(  I'm using 1.6.0.14

 

I suppose you'll just have to do the same within the module mail directories. 

Share this post


Link to post
Share on other sites

  • 2 weeks later...

I am a novice here but I think/thought I understood what I needed to do.

 

I Updated the 3 different php files. Modified just the test.html email originally via the translator area (using notepad++ then uploaded via ftp).  Now when I go to send a test email, I get an error to "check my configuration."  My updated test email has the standard header and footer of the other emails.

 

The email still sends, but no header or footer on the test email at all.  I don't even see the oversized "Hello".  Just the "This is a test email, if...."

 

I edited the order_confirm email to be brackets "{ }" but it still delivered with the %7.

If I go in as if I wanted to edit the html file in prestashop, Viewing the email shows %7 but html edit, when I go to edit the link is shows as {shop_url}

 

Version 1.6.0.14, with the default bootstrap theme installed using the 1 click install by the host.  The email issue is the last thing I am trying to sort out before it goes live.

 

Restored the tool.php to original and the error goes away on sending a test email but of course I still do not have clickable links.

 

Edit: I was able to edit the "send to a friend" with all of the 3 php modules updated and it worked. but now I get an error when  adding anything to the shopping cart.

 

Final edit (I hope): I don't know what HTMLPurifier_standalone.php modification is supposed to do, but with it, my site crashes. So far it looks like just the 2 mods fixed my issue.

Edited by dlcramer (see edit history)

Share this post


Link to post
Share on other sites

  • 2 weeks later...

if i understood correctly, it can't be solved if you use prestashop CLOUD....

so we need to wait until we get a update....correct?

juweeltje

Update:  I have made a video which explains how you can easly fix this error for cloud and self hosted presta webshops.

 

You are not able to access the sub-map your_store_url/Classes/,

therefore you cannot apply the update for cloud hosted web-shops.

 

You will have to be patience and wait for the cloud store to upgrade.

I am a novice here but I think/thought I understood what I needed to do.

 

I Updated the 3 different php files. Modified just the test.html email originally via the translator area (using notepad++ then uploaded via ftp).  Now when I go to send a test email, I get an error to "check my configuration."  My updated test email has the standard header and footer of the other emails.

 

The email still sends, but no header or footer on the test email at all.  I don't even see the oversized "Hello".  Just the "This is a test email, if...."

 

I edited the order_confirm email to be brackets "{ }" but it still delivered with the %7.

If I go in as if I wanted to edit the html file in prestashop, Viewing the email shows %7 but html edit, when I go to edit the link is shows as {shop_url}

 

Version 1.6.0.14, with the default bootstrap theme installed using the 1 click install by the host.  The email issue is the last thing I am trying to sort out before it goes live.

 

Restored the tool.php to original and the error goes away on sending a test email but of course I still do not have clickable links.

 

Edit: I was able to edit the "send to a friend" with all of the 3 php modules updated and it worked. but now I get an error when  adding anything to the shopping cart.

 

Final edit (I hope): I don't know what HTMLPurifier_standalone.php modification is supposed to do, but with it, my site crashes. So far it looks like just the 2 mods fixed my issue.

 

Can you post a printscreen of your e-mail editor, and the e-mail you receive.

Edited by Crezzur (see edit history)

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Crezzur,

 

it works , even with the could version....exept, one.....; the "Shipped" mail...; even when i change  it to }.... is keeps geving me the b7% .

Al the rest works fine now

 

I have just tested "Core emails" -> "shipped" on a clean install of the prestashop version 1.6.0.9 with my solution added and i have no problems changing the brackets of this template without braking the template. are you sure you have replaced the %7b with brackets in that template ?

Share this post


Link to post
Share on other sites

The problem is that the editor of email templates (the famous TinyMCE), when you edit a link, always replaced in the URL field the characters "{" and "}" to "% 7B" and "% 7D" for hard you try, and always travels URL link wrong because it is not the variable to put the correct URL.

 

The trick is 100% reliable to solve it and that I have solved my problem is this.

 

All email templates are HTML files in the "mail" folder of your template and generic Prestashop. Also you find this folder on the modules that are associated sending emails. Well, like HTML files without more, you can edit them there for not using TinyMCE editor. There you can successfully create URLs of the links, putting well the characters "{" and "}". Then save changes and upload the html file via FTP, substituting there. So, you get to leave the HTML file you want and well done.

Share this post


Link to post
Share on other sites

Could you send me a login for you backoffice so i can thale a quick look ?

 

 

The problem is that the editor of email templates (the famous TinyMCE), when you edit a link, always replaced in the URL field the characters "{" and "}" to "% 7B" and "% 7D" for hard you try, and always travels URL link wrong because it is not the variable to put the correct URL.
 
The trick is 100% reliable to solve it and that I have solved my problem is this.
 
All email templates are HTML files in the "mail" folder of your template and generic Prestashop. Also you find this folder on the modules that are associated sending emails. Well, like HTML files without more, you can edit them there for not using TinyMCE editor. There you can successfully create URLs of the links, putting well the characters "{" and "}". Then save changes and upload the html file via FTP, substituting there. So, you get to leave the HTML file you want and well done.

 

 

Well,

when i download the "shipped.html" file from FTP, i do see my "followup" link correctly whit {} en no % , but still it dosn't work

 

6fxmvc.jpg

Share this post


Link to post
Share on other sites

Hi,

Is there any way to do same with "core emails" ??

 

Though i have edited templates manually , still struggle to enable hyper link for new password generation url & coustomer message reply link in emails sent to coustomer .

 

Also i use version 1,6.0.14 & uploading  file AdminTranslationsController is diabling my translations tab from localization menu (back panel of prestashop)  i.e when i click translations tab after uploading the file i see blank white page .]

 

Any help is appriciated . :rolleyes:

Share this post


Link to post
Share on other sites

Hi Crezzur,

 

thanks for the solution, but in our case it didn't work. I copied the PHP in the folder /ULR/controllers/admin but afterwards I can't open the translation side in the backoffice of prestashop (version 1.6.014). Just a white screen. So I need to reverse the chances.

What went wrong?

 

Kind regards

Frank

Hey all,

 

I noticed several people are having issue's when translating or editing templates the url's in the edited e-mail template are broken.

When you edited a template url brackets " { " and " } " are replaced by %7B and %7D.

 

Example: {weburl} changes to %7Bweburl%7D

 

How to solve this problem? (Updated 15/07/2015)

(This fix works also for cloud based web-shops!)

 

Watch this video for the steps: https://www.youtube.com/watch?v=nwb050tdyfM

File used in video: attachicon.gifAdminTranslationsController.php

 

IMPORTANT NOTE:  after adding this file you have to replace %7B and %7D. with " { " and " } " (Now they wont change anymore!)

Please check every e-mail template you have an issue with that the bracket are not changed.

 

Please note: Issue should disappear with newest version of prestashop: http://forge.prestashop.com/browse/PSCSX-4594?jql=

 

Enjoy your prestashop!

~ Crezzur ~

 

PS: Don't forget to like my post if this topic has solved your issue ;)

Share this post


Link to post
Share on other sites

Hi all,

 

I used the technique proposed by Crezzur in the youtube video with the override file and it did not work as no matter how hard you try, the %7B url %7D/ would always come back in the email templates.

 

Then I used the other technique:

YOUR_WEBSITE_ROOT/controllers/admin/AdminTranslationsController.php
 
Search for:
file_put_contents($path.$mail_name.'.'.$type_content, Tools::purifyHTML($content));
Replace that line with:
file_put_contents($path.$mail_name.'.'.$type_content, $content);
Note: after adding this change you have to replace %7B and %7D. with " { " and " } " (Now they wont change anymore!)

This time it worked well for the permanent replacement of  %7B and %7D with " { " and " } "

 

However, my shop logo still looks as a broken link in all received emails so that doesnt really help me much and now I still don't have a clue how to fix it :(

 

PS 1.6.0.14

Edited by MilkSheikh (see edit history)

Share this post


Link to post
Share on other sites

Edit:


 


In classes/Mail.php


 


Replace


  1. if (isset($logo))
  2. $template_vars['{shop_logo}'] = $message->attach(new Swift_Message_EmbeddedFile(new Swift_File($logo), null, ImageManager::getMimeTypeByExtension($logo)));

By :


  1. if (isset($logo))
  2. $template_vars['{shop_logo}'] = Tools::getShopDomain(true, true).__PS_BASE_URI__.'img/'.Configuration::get('PS_LOGO', null, null, $id_shop);

 


Your logo won't be in attachement anymore and will be in the header of the emails. After that you still need to replace manually all the %7B and %7D with " { " and " } " in the email templates.


 


So if anyone has a trick for a quick mass edit I am up for it


 


Cheers !


Share this post


Link to post
Share on other sites

Hi all,

 

I used the technique proposed by Crezzur in the youtube video with the override file and it did not work as no matter how hard you try, the %7B url %7D/ would always come back in the email templates.

 

Then I used the other technique:

 

YOUR_WEBSITE_ROOT/controllers/admin/AdminTranslationsController.php
 
Search for:
file_put_contents($path.$mail_name.'.'.$type_content, Tools::purifyHTML($content));
Replace that line with:
file_put_contents($path.$mail_name.'.'.$type_content, $content);
Note: after adding this change you have to replace %7B and %7D. with " { " and " } " (Now they wont change anymore!)
This time it worked well for the permanent replacement of  %7B and %7D with " { " and " } "

 

However, my shop logo still looks as a broken link in all received emails so that doesnt really help me much and now I still don't have a clue how to fix it :(

 

PS 1.6.0.14

Did you clear your cache after my suggested fix ?

Share this post


Link to post
Share on other sites

I did that and it didn't fix my problem, Email links are still not working...can you help?

 

I know this might be coming a little bit late but I still felt I should post it as I have been battling this problem for over 3 months now. Tried the fix above to no avail. I actually thought I have replaced all the %7B and %7D until moments ago when I accidentally looked at the "image" link on the "Edit HTML version" tab of the email templates and realised that the "{" and "}" have also been replaced with %7B and %7D. I changed these back to the normal "{" and "}" and bingo - problem solved.

 

I am so happy.

 

Thanks to all contributors. 

Share this post


Link to post
Share on other sites

MilkSheikh,

 

Thank you VERY MUCH! You helped me a lot! This works for me:

 

YOUR_WEBSITE_ROOT/controllers/admin/AdminTranslationsController.php

Search for:
file_put_contents($path.$mail_name.'.'.$type_content, Tools::purifyHTML($content));
Replace that line with:
file_put_contents($path.$mail_name.'.'.$type_content, $content);
Note: after adding this change you have to replace %7B and %7D. with " { " and " } " (Now they wont change anymore!)

  • Like 1

Share this post


Link to post
Share on other sites

Did you try that for logo in attachement ? It worked for me:

 

In classes/Mail.php

 

Replace

  1. if (isset($logo))
  2. $template_vars['{shop_logo}'] = $message->attach(new Swift_Message_EmbeddedFile(new Swift_File($logo), null,ImageManager::getMimeTypeByExtension($logo)));

By :

  1. if (isset($logo))
  2. $template_vars['{shop_logo}'] = Tools::getShopDomain(true, true).__PS_BASE_URI__.'img/'.Configuration::get('PS_LOGO', null, null, $id_shop);

Share this post


Link to post
Share on other sites

  • 1 month later...
  • 2 weeks later...