[SOLVED] message: use of undefined constant intl_idna_variant_uts46 - assumed 'intl_idna_variant_uts46'
I was working on a project that works perfectly on my local. I moved the project to a shared server and I start getting this funny error "message: use of undefined constant intl_idna_variant_uts46 - assumed 'intl_idna_variant_uts46'". I checked everywhere and it seems it is a known issue but very few fix worked. I got this fix below to work so I decided to keep this here for myself later and anyone looking for a solution that worked
In system/libraries/Email.php, change the valid_email function to below
public function valid_email($email)
{
if (function_exists('idn_to_ascii') && strpos($email, '@'))
{
list($account, $domain) = explode('@', $email, 2);
$domain = defined('INTL_IDNA_VARIANT_UTS46')
? idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46)
: idn_to_ascii($domain);
$email = $account.'@'.$domain;
}
return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
}
In system/libraries/Form_validation.php, change the valid_email function to below
public function valid_email($str)
{
if (function_exists('idn_to_ascii') && preg_match('#\A([^@]+)@(.+)\z#', $str, $matches))
{
$domain = defined('INTL_IDNA_VARIANT_UTS46')
? idn_to_ascii($matches[2], 0, INTL_IDNA_VARIANT_UTS46)
: idn_to_ascii($matches[2]);
$str = $matches[1].'@'.$domain;
}
return (bool) filter_var($str, FILTER_VALIDATE_EMAIL);
}
I hope this helps someone.