Eric Belair
Eric Belair

Reputation: 10692

How can I display email formatted as "FirstName LastName <[email protected]>" in HTML?

I am trying to display an email formatted as "FirstName LastName <[email protected]>" in HTML, and it is only displaying "FirstName LastName".

Pseudo-code:

<cfset LOCAL.From = "FirstName LastName <[email protected]>" />
<cfoutput>#Local.From#</cfoutput>

I know I can replace the less-than and greater-than signs with lt; and gt;, but I'm looking for a better way than Replace(Replace(LOCAL.Form, "<", ";lt;"), ">", "&gt;").

I'm not very good with Regular Expressions, if that's the way to go, so show me a good RegEx for this, if you'd like.

Or, if this can be done simply with some ColdFusion function, that's great too.

Upvotes: 1

Views: 230

Answers (2)

Josh Siok
Josh Siok

Reputation: 936

Assuming you are getting the FirstName and LastName variables from somewhere, you need to specify them as output. The way you've coded it, the string would always be the same and not dynamic.

<cfset FirstName = "John">
<cfset LastName = "Doe">
<cfset LOCAL.From = "#FirstName# #LastName# <#FirstName##LastName#@domain.com>" />
<cfoutput>#HTMLEditFormat(Local.From)#</cfoutput>

Upvotes: 0

Daniel Schaffer
Daniel Schaffer

Reputation: 57832

You're looking for HTML encoding, rather than string replacement. Use HtmlEditFormat.

Possibly related: How to encode HTML form in coldfusion?

Upvotes: 2

Related Questions