79225154

Date: 2024-11-26 02:40:47
Score: 0.5
Natty:
Report link

In my experience, the CSS suggested in the previous answers won't work across all email clients. The most failsafe way to ensure that long strings (i.e. URL links) will wrap within a container element is to dynamically insert <br> elements into a display version of the string. If a user copy & pastes the URL string into an address bar, the line breaks are ignored.

The following code is in Ampscript, however the principles remain the same for other languages.

VAR @link, @linkDisplay, @linkLen, @linkSegmentNo, @linkSegmentLen, @linkSub
 
SET @linkLen = length(@link)
SET @linkSegmentLen = 52
SET @linkSegmentNo = FormatNumber(subtract(divide(@linkLen, @linkSegmentLen), 0.5), "N0", "en-AU")

FOR @i = 0 TO @linkSegmentNo DO
 SET @linkSub = Substring(@link, Add(Multiply(@i, @linkSegmentLen), 1), @linkSegmentLen)
 SET @linkDisplay= Concat(Concat(@linkBreak, @linkSub), "<br>")
NEXT @i

<a href="@linkURL">@linkDisplay</a>

Where the @link is the original string and @linkDisplay is the string with <br> elements added at a preset segment length (the number of characters to include before adding the line break).

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @link
  • User mentioned (0): @linkDisplay
  • Low reputation (1):
Posted by: RyanLock