php-simple-mail
php-simple-mail copied to clipboard
PHP 8.1 - Deprecated: Constant FILTER_SANITIZE_STRING is deprecated
Php 8.1 issues a deprecation warning when sending an email. This is because of FILTER_SANITIZE_STRING in filterName().
// OLD
public function filterName($name)
{
$rule = array(
"\r" => '',
"\n" => '',
"\t" => '',
'"' => "'",
'<' => '[',
'>' => ']',
);
$filtered = filter_var(
$name,
FILTER_SANITIZE_STRING,
FILTER_FLAG_NO_ENCODE_QUOTES
);
return trim(strtr($filtered, $rule));
}
Changing this function to below solves this:
// CHANGED
public function filterName($name)
{
$rule = array(
"\r" => '',
"\n" => '',
"\t" => '',
'"' => "'",
'<' => '[',
'>' => ']',
);
$filtered = filter_var(
$name,
FILTER_UNSAFE_RAW,
FILTER_FLAG_STRIP_LOW
);
return trim(strtr($filtered, $rule));
}
P.S. Sorry, I am unable to provide a PR.