Skip to main content
December 30, 2008
Question

Spaces in URLS

  • December 30, 2008
  • 4 replies
  • 1504 views
When users on my site submit a report, an email is generated with cfmail that passes the URL where the report can be found.

On some of the URL strings there are spaces and the link within the mail is not accurate. It dies at the space...

Should I use URLEncodedFormat to solve this issue? I can't have any spaces in the URL or else it won't work correctly.
    This topic has been closed for replies.

    4 replies

    Inspiring
    December 30, 2008
    How are the spaces getting there to start with?
    Inspiring
    December 30, 2008
    Since you can't use HTML formatted emails, then you're initial assumption is correct. URLEncodedFormat() will properly convert spaces and other pesky URL characters so that any browser should properly handle the URL request.
    December 30, 2008
    That's a good idea... but many of the site users are old school and may not have html enabled email...
    Participant
    December 30, 2008
    Ok, since you're not wrapping in html format your sending as a plain text. So in your case the urlencodedformat won't be an option as it will just return a encoded format like (ie. ttp%3A%2F%2Fwww%2Egoogle%2Ecom%3Ftest%3Dtest%20test http://www.google.com?test=test%20test ) which won't do much for your receipient. So i would just do a replace on the space with %20 and that should work for html and plain text format.
    <cfset urltest = " http://www.google.com?test=test test">
    <cfset urltest = replace(urltest,' ','%20','all')>
    This should return in the email
    http://www.google.com?test=test%20test
    Participant
    December 30, 2008
    I would just make sure the cfmail has a type=html and i would wrap the url in a <a> tag. The browser will take care of the encoding.

    <cfset urltest = " http://www.google.com?test=test test">
    <cfmail to="email@email.com" from="email@email.com" subject="testing" type="html">
    <a href="#urltest#">#urltest#</a>
    </cfmail>