简体   繁体   中英

ampersand in php mail “FROM” header

OK, I am stumped. I have a client with an ampersand in the company name. Like "Bill & Bob Associates". So, I have a from line like:

 $headers  = "From: Bill & Bob Associates, LLC <info@billbob.com>\r\n";

The & is breaking the from in the email like such;

From: info@host.webhost.com,
&@host.webhost.com, Associates@host.webhost.com,
LLC <info@billbob.com>

Tried %26 and that did not work.

Any help would be appreciated.

could be like :

$headers = "From: ". mb_encode_mimeheader('Bill & Bob Associates, LLC', 'UTF-8', 'Q') ." <info@billbob.com>\\r\\n";

or you could try:

$headers = "From: =?UTF-8?B?". base64_encode('Bill & Bob Associates, LLC') ."?= <info@billbob.com>\\r\\n"

@nanocv was on the right track, but, the string was already in double quotes. But, going to a single quote, AND adding double quotes around the name did the trick, as in:

$headers    = 'From: "Bill & Bob, LLC" <ino@billbob.com>\r\n';

Which, now that I look at it, makes sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM