By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,017 Members | 1,238 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,017 IT Pros & Developers. It's quick & easy.

Angle brackets cause string to truncate

P: n/a
I am trying to build an email address in PHP code using v5.1.2. All
works well until I try to surround the email address with angle
brackets. Every method I try causes the email address to disappear
completely. I have to believe that this is a common problem, but I
can't find any answers in the PHP docs or in Google. Any insight
would be greatly appreciated. Below are some of my failed attempts.

$strAddressee = "$ContactName "."<"."$ContactEmail".">";
(brackets and email address disappear)

$strAddressee = "$ContactName <$ContactEmail>";
(brackets and email address disappear)

$strAddressee = "$ContactName \074 $ContactEmail \076";
(works, except for unwanted spaces between the brackets and address)

$strAddressee = "$ContactName \074{$ContactEmail}\076";
(brackets and email address disappear)

Apr 6 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
>I am trying to build an email address in PHP code using v5.1.2. All
>works well until I try to surround the email address with angle
brackets.
Have you considered viewing the result in something other than HTML?
(or using the "view source" function of your browser?) I believe
the string really is there; you <dead catjust don't see it
<dead catin a browser <dead cat>. When you read this, how many
dead cats are there in the previous sentence? There are three.
>Every method I try causes the email address to disappear
completely. I have to believe that this is a common problem, but I
can't find any answers in the PHP docs or in Google. Any insight
would be greatly appreciated. Below are some of my failed attempts.

$strAddressee = "$ContactName "."<"."$ContactEmail".">";
(brackets and email address disappear)

$strAddressee = "$ContactName <$ContactEmail>";
(brackets and email address disappear)

$strAddressee = "$ContactName \074 $ContactEmail \076";
(works, except for unwanted spaces between the brackets and address)

$strAddressee = "$ContactName \074{$ContactEmail}\076";
(brackets and email address disappear)
If you want to output this string on a web page and *only* on a
web page, try:

$strAddressee = "$ContactName &lt;$ContactEmail&gt;";

but if you put that in mail headers it will probably screw up.
Apr 7 '07 #2

P: n/a
Gordon Burditt wrote:
>I am trying to build an email address in PHP code using v5.1.2. All
works well until I try to surround the email address with angle
brackets.

Have you considered viewing the result in something other than HTML?
(or using the "view source" function of your browser?) I believe
the string really is there; you <dead catjust don't see it
<dead catin a browser <dead cat>. When you read this, how many
dead cats are there in the previous sentence? There are three.
>Every method I try causes the email address to disappear
completely. I have to believe that this is a common problem, but I
can't find any answers in the PHP docs or in Google. Any insight
would be greatly appreciated. Below are some of my failed attempts.

$strAddressee = "$ContactName "."<"."$ContactEmail".">";
(brackets and email address disappear)

$strAddressee = "$ContactName <$ContactEmail>";
(brackets and email address disappear)

$strAddressee = "$ContactName \074 $ContactEmail \076";
(works, except for unwanted spaces between the brackets and address)

$strAddressee = "$ContactName \074{$ContactEmail}\076";
(brackets and email address disappear)

If you want to output this string on a web page and *only* on a
web page, try:

$strAddressee = "$ContactName &lt;$ContactEmail&gt;";

but if you put that in mail headers it will probably screw up.

or

$strAddressee = htmlspecialchars("$ContactName <$ContactEmail>");

Louise
Apr 7 '07 #3

P: n/a
Gordon Burditt wrote:
>I am trying to build an email address in PHP code using v5.1.2. All
works well until I try to surround the email address with angle
brackets.

Have you considered viewing the result in something other than HTML?
(or using the "view source" function of your browser?) I believe
the string really is there; you <dead catjust don't see it
<dead catin a browser <dead cat>. When you read this, how many
dead cats are there in the previous sentence? There are three.
>Every method I try causes the email address to disappear
completely. I have to believe that this is a common problem, but I
can't find any answers in the PHP docs or in Google. Any insight
would be greatly appreciated. Below are some of my failed attempts.

$strAddressee = "$ContactName "."<"."$ContactEmail".">";
(brackets and email address disappear)

$strAddressee = "$ContactName <$ContactEmail>";
(brackets and email address disappear)

$strAddressee = "$ContactName \074 $ContactEmail \076";
(works, except for unwanted spaces between the brackets and address)

$strAddressee = "$ContactName \074{$ContactEmail}\076";
(brackets and email address disappear)

If you want to output this string on a web page and *only* on a
web page, try:

$strAddressee = "$ContactName &lt;$ContactEmail&gt;";

but if you put that in mail headers it will probably screw up.

if you wanted to write out the strAddressee as debug on an html page and
it had the angle brackets in, you would have to do:

echo htmlentities($strAddressee);

That would encode the debug so you could see the angle brackets.
Apr 7 '07 #4

P: n/a
Have you considered viewing the result in something other than HTML?
(or using the "view source" function of your browser?) I believe
the string really is there; you <dead catjust don't see it
<dead catin a browser <dead cat>. When you read this, how many
dead cats are there in the previous sentence? There are three.
Nice catch Gordon! The address is there, just hidden. I was using
the browser to test the output, but the actual target is the mail()
function. It never occurred to me that the browser would interpret
the email address in brackets as an HTML tag. I guess what you see is
not always what you get. Thanks for your help, and thanks to the
other posters.

Apr 7 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.