Jump to content

PHP code inside the EMAIL template, how do I accomplish that? Unicode domain to IDN ASCII


Recommended Posts

Hi All

 

Stumbled upon this old post.

I want to add the following PHP code to an email template I have.

 

The code convert an unicode domain name domain to an IDNA ASCII-compatible format.

When I add the code to the template I just get an error, so I suspect I am doing it wrongly.

 

{php}
echo idn_to_ascii('$service_domain');
{/php}

 

I have pasted an example below.

 

<?php

echo idn_to_ascii('täst.de'); 

?>

 

Gives the output : xn--tst-qla.de

 

I look forward to hear from you.

 

- Tim

Edited by WHMCS ChrisD
Added coding blocks
Link to comment
Share on other sites

Hi TIm,

 

I can see two potential issues with this...

 

1. in order for idn_to_ascii to work, you will likely have to enable 'intl' in your PHP settings.

2. as it's just a PHP function, you should be able to call it directly in Smarty without the need for {php} tags... e.g, either of the following should work and give the same output...

 

php = {php}echo idn_to_ascii('ჰელო.გე');{/php}
smarty = {idn_to_ascii('ჰელო.გე')}

 

7aKOiBs.png

... and given the option of using either, go with Smarty... though bear in mind that you will need to update your Smarty Security Policy to cover it's use in the email templates. :idea:

Link to comment
Share on other sites

  • 2 weeks later...

Hi Brian

 

To understand the Smarty Security Policy, I would need to add the following to my configuration file to be able to use the idn_to_ascii within the email templates.

 

// Smarty custom email based template policy:
$smarty_security_policy = array(
   'mail' => array(
       'php_functions' => array(
           'idn_to_ascii',
       ),
   ),
);

 

- Tim

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated