I'm trying to generate email messages. The recipient's email
address and name are specified by a user. What is the correct way to do this with PHP:
$to_header = "To: $name <$email>" # incorrect!
I already use a decent method for validating the email addressess (let's not go to that now...), but how do I properly encode $name with eg. QP when needed? For example, if the recipient is called "Foo Bär", I should produce (eg.) something like:
To: =?utf-8?Q?Foo_B=C3=A4r?= <
[email protected]>