MisterPresta Posted December 20, 2013 Share Posted December 20, 2013 I am trying to send an email to a customer from the "View" page for an order (where is says "click here to add a comment or send a message to the customer"). I am using just text email, not HTML. When I insert a URL (link) in the email, it is HTML-entity encoded ("&" becomes "&", etc.). This makes the URL link I inserted unusable by the recipient. Why are text emails being encoded for HTML entities? How do I prevent this from happening? Link to comment Share on other sites More sharing options...
MisterPresta Posted December 20, 2013 Author Share Posted December 20, 2013 I have some additional information/comments about this. I have version 1.5.6.0 installed. I think it is a bug (maybe not technically a coding bug, but it seems conceptually to not be quite right). I would like the opinion of someone with more experience with PrestaShop to agree or disagree with me. If it is indeed a bug,how do I report it? In /controllers/admin/AdminOrdersController.php, near line 430, the following call is made unconditionally whether the email type is TYPE_HTML, TYPE_TEXT, or TYPE_BOTH: htmlentities(Tools::getValue('message'), ENT_COMPAT, 'UTF-8'); Then if the email type is either TYPE_HTML or TYPE_BOTH, the following call is also made which adds HTML <br> tags: Tools::nl2br($customer_message->message) The resulting message is placed into the $varsTpl array (as '{$message}') to be used as replacement text in the email template(s). There are 2 problems. 1) HTML entities are always encoded for text mail (my current problem) 2) if TYPE_BOTH is selected, then the text mail ends up with <br> tags. I can think of several ways to solve both problems. I am not familiar enough with the design philosophy to know which is better, whether these cause problems I did not consider, or whether there are additional options. I prefer the second option because it preserves flexibility in hooks: 1) Don't manipulate the message text (i.e., what was entered into the form, not the template) until it is inserted into the email message (in mail.php). Insert the text version first (replace {message} in template.txt), then encode entities and add <br> to {message} before processing the html template. This centralizes the checking of the email type which is currently distributed. The drawback is that this negatively affects hooks by forcing everyone to do it the same way. 2) Code that calls Mail::Send(...) creates 2 replacement strings: {message} and {html_message}. This lets the caller (possibly in an override class) do things its own way (though you would expect most people to encode only {html_message}). The drawback is that you must change the HTML template to use {html_message} instead of {message}. Since the template text is loaded into memory (and already processed somewhat-- to remove HTML from the .txt template, for example), you could replace '{message}' with '{html_message}' in the .html template (do this in Mail.php) for backward compatibility. Any thoughts, anyone? Link to comment Share on other sites More sharing options...
Recommended Posts