-1

For a new project which is done in PHP with the laravel framework we need to give every user an email address out of his first and surname. There will be no user without a firstname and surname.

This will be the syntax of the email address: firstname.surname@ourdomain.com

So here are the user-given variables firstname and surname.

The problem here is that the firstname and surname is not standardized. For example there can be the character "é" or the umlaut "ü" etc. etc.

What would be the best way to convert the combination of "firstname.surname" to a RFC 5322 compliant address?

Thanks in advance!

bueny
  • 1
  • 2
  • Umlauts and the like ARE RFC5322 compliant. See https://stackoverflow.com/questions/15121359/are-international-characters-e-g-umlaut-characters-valid-in-the-local-part-of "as long as the mail exchanger responsible for the email address supports the UTF8SMTP extension" – stokoe0990 Jun 21 '19 at 15:09
  • There is [iconv](https://www.php.net/manual/en/function.iconv.php) – stokoe0990 Jun 21 '19 at 15:11

1 Answers1

2

Using iconv you can convert the character sets of strings.

$string = "Löic René";
$output = iconv("UTF-8", "ASCII//TRANSLIT", $string);

The above code will convert the input to "Loic Rene".

stokoe0990
  • 443
  • 3
  • 10
  • I am getting the following PHP notice and no output "Loic Rene": `Notice: iconv(): Detected an illegal character in input string in /var/www/html/page/test.php on line 3` – bueny Jun 23 '19 at 22:18