How to format an email address line (with name) with PHP?

Posted by nbr on Stack Overflow See other posts from Stack Overflow or by nbr
Published on 2010-04-22T07:53:32Z Indexed on 2010/04/22 8:13 UTC
Read the original article Hit count: 187

Filed under:
|

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]>

© Stack Overflow or respective owner

Related posts about php

Related posts about email