How to Create an SMS Link With a Prefilled Message

Learn how to encode a prefilled SMS link, provide a plain-text fallback, and test it across mobile devices, email, websites, and QR codes.

Published
Reading time
6 min read
How to Create an SMS Link With a Prefilled Message
On this page

An SMS link can invite someone to open their messaging app with a phone number and message filled in. This guide shows how to create an SMS link with a prefilled message, encode special characters, and check it in the places your audience will use it.

The example has not been tested on current iOS or Android devices. Before publishing a campaign, test it on the devices and apps your audience uses; an sms: URI does not guarantee a particular messaging-app experience.

Key Takeaways

  • A common link format is sms:PHONE_NUMBER?body=ENCODED_MESSAGE.
  • Encode the message text so spaces, punctuation, and non-ASCII characters remain part of the message rather than being interpreted as URI syntax.
  • A link may open a draft, behave differently, or not work, depending on the device and the app opening it. It does not send the message automatically.
  • Show the phone number and suggested message as a fallback, and test from the actual website, email, or QR-code flow.

Start with sms:, followed by the recipient's phone number. Add ?body= and the URL-encoded message. For example, this link uses a fictional number and the message Hi there! Café & cake?:

sms:+12025550123?body=Hi%20there!%20Caf%C3%A9%20%26%20cake%3F

The number uses an international-style format: a plus sign, country code, and remaining digits. Replace it with the number your organization is authorized to use and can receive messages on.

In the message, %20 represents a space, %C3%A9 represents é encoded as UTF-8, %26 represents &, and %3F represents ?. The exclamation mark is left unescaped by the JavaScript encoder used below.

The URI describes a recipient and message; it is not a promise that a messaging app will accept both. The person still needs to review and send any draft that opens.

Advertisement

Encode the message

You can generate the message portion in a browser's developer console. Replace the two values with your own number and message, then copy the resulting URI from the console:

const phoneNumber = "+12025550123";
const message = "Hi there! Café & cake?";
const smsLink = `sms:${phoneNumber}?body=${encodeURIComponent(message)}`;

console.log(smsLink);

encodeURIComponent encodes the message as a URI component. Encode the message once, not the entire URI: encoding the whole link would also encode characters such as : and ? that provide its structure. If you edit the message, generate the encoded value again rather than manually appending unencoded text.

This example uses a fixed, trusted phone number. If you accept numbers from users, validate them according to your application's requirements instead of inserting arbitrary text into a link.

For a website, use an ordinary HTML link and keep the number and suggested message visible nearby:

<a href="sms:+12025550123?body=Hi%20there!%20Caf%C3%A9%20%26%20cake%3F">
  Text us about the event
</a>
<p>Or text +1 202-555-0123 with: Hi there! Café &amp; cake?</p>

Replace the fictional number and message in both places. The visible text lets someone manually start a message if their browser, email app, QR scanner, or messaging app does not handle the link as expected. In HTML, the visible ampersand is written as &amp;.

For email, use the same URI as the button or link destination if your email editor permits it, then send yourself a real test email. For a QR code, check whether the scanner recognizes the sms: destination; alternatively, link the QR code to a page that displays the button and fallback.

Account for mobile differences

?body= is the example's message separator. You may encounter examples that use &body= instead. An ampersand normally separates parameters after a query has already begun; do not assume an alternative form will work across apps without testing it in your intended context.

Likewise, don't assume that every app will populate the recipient field, preserve the message exactly, or open a draft. Multiple recipients introduce another compatibility variable, so use one recipient for this basic campaign and test any multi-recipient flow separately. A phone may also prompt the user to choose an app or decline to open the link.

No current iOS-versus-Android behavior is asserted here: those platform checks were not available for this article. Treat a successful test as evidence for the specific device, app, and campaign context tested—not a guarantee for every recipient.

Advertisement

Pre-campaign testing checklist

Before publishing, use a test number you control or are authorized to message. Repeat these checks on representative current iOS and Android devices, recording the device, operating system, and apps used:

  1. Open the actual campaign. Follow the link from the published or staging website, a received test email, or a scan of the actual QR code—not just from a console or address bar.
  2. Check the recipient. Confirm the intended number appears in the recipient field and that no unintended recipients are added.
  3. Check the message. Confirm spaces, punctuation, accented characters, and any emoji appear as intended, with no literal encoding sequences or missing text.
  4. Check the draft flow. Note whether a messaging app opens, whether the draft is editable, and what happens if the user cancels. Send only an authorized test message.
  5. Exercise the fallback. Confirm the displayed number and plain-text message match the link and can be used manually.
  6. Repeat after changes. Re-test if you change the number, copy, email template, landing page, QR destination, or campaign delivery method.

If a channel blocks or alters the link, keep the visible fallback and consider directing users to a page with clear instructions. Don't claim that a draft will open on a particular platform until you have verified your own flow there.

Common Mistakes

  • Leaving the message unencoded. An & or ? in the text can be mistaken for URI structure.
  • Double-encoding the message. Encoding already encoded text can leave recipients seeing sequences such as %20 instead of spaces.
  • Using a link as the only contact option. Some contexts cannot open it or may omit part of the draft.
  • Assuming the message is sent on tap. The link is an invitation to compose; the user controls sending.
  • Putting sensitive information in the prefill. Link destinations can be exposed in page markup, campaign tooling, or QR codes. Use a generic message instead of personal details or credentials.

Best Practices

Keep the proposed message short and understandable, identify who will receive it, and make clear that the user is initiating a text. Standard messaging charges may apply. For promotional campaigns, follow the consent, privacy, and messaging rules applicable to your audience and location; an SMS link alone does not establish permission to send future marketing messages.

Conclusion

Create the link with a phone number and an encoded body, then provide the same information as visible text. Verify the complete experience in each campaign channel and on representative mobile devices before relying on it.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.