Search code examples
phpphpmailer

Uppercase username in post


I'm sending an email which signs off with the user's name. I've tried using $uppercaseinviter = [ucwords ("{$_SERVER['PHP_AUTH_USER']}")]; and $uppercaseinviter = $_POST[ucwords ("{$_SERVER['PHP_AUTH_USER']}")];.

In the email body I'm just using <p>{$uppercaseinviter}</p>. The first method above sends the text in the email as ucwords ("name"); and the second method sends it as Array with Notice: Array to string conversion. The first method gives a notice for undefinded variable Name so has uppercased it.

I can output the name in lowercase but I need the first letter of the name to be uppercase and I'm not too sure where I'm going wrong as the first method does uppercase, just not output and the second sends the word Array instead.


Solution

  • You're adding too much to the code. The first you're making an array, the second you're trying to pull it out of $_POST. You don't even need the quotes and braces, it's just unnecessary. If the value is in PHP_AUTH_USER, all you need is

    $uppercaseinviter = ucwords($_SERVER['PHP_AUTH_USER']);