htmlioshyperlinksms

How to pre-populate the sms body text via an html link


How to use an html link to open the sms app with a pre-filled body?

Everything I have read seems to indicate that sms:18005555555?body=bodyTextHere

Should work, but on the iPhone, this doesn't work. If I take out the ?body=bodyTextHere, and just use sms:phonenumber, it works.

I have seen several instances where QR codes do this through a safari link. How are they able to pre-populate the body text?


Solution

  • It turns out this is 100% possible, though a little hacky.

    If you want it to work on Android you need to use this format:

    <a href="sms:/* phone number here */?body=/* body text here */">Link</a>

    If you want it to work on iOS, you need this:

    <a href="sms:/* phone number here */;body=/* body text here */">Link</a>

    Live demo here: http://bradorego.com/test/sms.html (note the "Phone and ?body" and "Phone and ;body" should autofill both the to: field and the body text. View the source for more info)

    UPDATE:

    Apparently iOS8 had to go and change things on us, so thanks to some of the other commenters/responders, there's a new style for iOS:

    <a href="sms:/* phone number here */&body=/* body text here */">Link</a>

    (phone number is optional)