How to pre-populate the sms body text via an html link
Solution 1
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)
Solution 2
I know this is an old thread but stumbled upon it and found that some parts are no longer relevant.
I've found that if you want to just per-populate the text without adding a phone number, you can do the following:
sms:?&body=/* message body here */
Solution 3
For iOS 8, try this:
<a href="sms:/* phone number here */&body=/* body text here */">Link</a>
Switching the ";" with a "&" worked for me.
Solution 4
Just put all of the symbols in this order (I only tested it in this order since it makes the most sense code-wise to me).
Notice for the body link... I just put... ;?&body=
. Also, notice that I have found I needed to use %20
for any spaces.
I have tested it on my iphone (v. 9.2) and another android and it works just fine.
This will solve the issue with having to hack it for different devices. I have no artifacts when I tested it in the SMS.
<a href="sms:19131234567;?&body=Question%20from%20mywebsite.com.%20%20MY%20MESSAGE%20-%20" title="Click here to TEXT US gallery token needs updating!">Send me SMS</a>
Solution 5
There is not need for two separate anchor tags for Android and iOS. This should help.
// Without Contact Number
<a href="sms:?&body=message">Text Message</a>
// With Contact Number
<a href="sms:1234567890;?&body=message">Text Message</a>
// Works on both Android and iOS
merlincam
Updated on July 08, 2022Comments
-
merlincam almost 2 years
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?
-
sparkyspider about 12 yearsIs that Objective C? How do you call that from JavaScript or use it in HTML? Sounds impossible?
-
ouah over 10 yearsOn iOS it looks like the format is: <a href="sms:[phone number];body=body text">Link</a>. Notice no square brackets on the body.
-
Brad Orego over 10 yearsAh, whoops. The square brackets aren't part of the format - that's where you should be putting in those values. I changed them to comments so hopefully it's a little clearer
-
Harikrishnan over 10 yearsWorked like a charm.Thank you so much for the live demonstration.+100
-
Brad Orego over 10 yearsCan this please be un-marked as accepted? This doesn't at all answer the question. I actually posted something that does work and does answer the question.
-
MMachinegun over 10 yearsseems to be working now. Hm weird. But cool that it's also possible for iOS
-
Brad Orego over 10 yearsNote: I haven't tested these on the latest OS versions (iOS7/the iPhone 5S/5C and Android 4.4). There are some reports that they might not be working anymore, especially with Android's switch to using Hangouts instead of a native SMS app. I'll look into it when I have the chance.
-
MMachinegun over 10 yearsI took a look now because it sometimes was working and sometimes not, which seemed weird. My findings: If you dial a number you have at least sent one SMS before, the link works fine with "body". If it's a complete new number you're out of luck and you only get the number :(
-
David C about 10 yearsWorks on most android, and IOS 5 and 6. Does not work on IOS 7.
-
Kirk Hammett about 10 yearsthis page is not accessible anymore
-
Uirri almost 10 yearsI did not get the body text even though it was a number I have sent plenty of SMSs to and have stored in Contacts. (Tested on iPhone 5S)
-
jefeman about 9 yearsThe android one does not appear to work if your device opens to hangouts. It will pass in the phone number, but not the body.
-
Greg Johnson about 9 yearsFor those still looking, it turns out with iOS 8 the syntax changed to <a href="sms:[phone number]&body=body text">Link</a>, where [phone number] is optional. TL;DR: iOS change ; to &.
-
Greg Johnson about 9 yearsThat's no longer true with iOS8. You can send <a href="sms:[phone number]&body=body text">Link</a> - the ampersand precedes the body=. Syntactically confusing, yes, but it's working for me and the body populates with the desired message.
-
fregante almost 9 yearsBig note: the app that handles the
sms
URI can be changed on Android and many manufacturers do this; therefore while it may work on a specific device/app, it may not work on another (or simply after an update). My suggestion is to never use this on Android unless you're only setting the phone number; only use it on iOS versions and non-Android platforms that you've tested. -
Strikers over 8 yearscan I add new line char in the body
-
paaacman over 8 years@OrangeDog see my answer for iOS 7 stackoverflow.com/questions/6480462/…
-
paaacman over 8 yearsFor iPhone4, see my answer bellow stackoverflow.com/questions/6480462/…
-
Manish Ahuja about 8 years@strikers I'm also having issue adding a new line character. Were you able to resolve that?
-
SIVAKUMAR.J about 8 yearsThis information i am searching for my project.Its very usefull for deeplink concepts in android
-
Bidstrup almost 8 yearsDo you know about windows phone?
-
Rob Dawson over 7 yearsfwiw I've just tested this on iOS 10 and it still works :).
-
Nicodemuz over 7 yearsConfirmed that iOS 10.2 doesn't support a "body" part as described in the link above.
-
Bruno Lemos almost 7 yearsIs there any way to the cursor start in the position 0? I don't want it in the end of the body text
-
ibex almost 7 yearsJust removing the number and leaving the semicolon (sms:;?&body=Questi..) worked on android 7 native messenger, when I didn't want the number to pre-populate
-
DMEM over 6 years@BradleyOrego On iPhones: This works perfectly fine if the SMS app was already opened in the background. If it wasn't, I'm just getting the app to be opened on my phone, without phone number or message body. Any ideas?
-
DMEM over 6 years@landen This works perfectly fine if the SMS app was already opened in the background. If it wasn't, I'm just getting the app to be opened on my phone, without phone number or message body. Any ideas?
-
Lucbug over 6 yearsFollowing on what @bfred.it said, the syntax even changes for different platforms. You can check the challenge section of this article.
-
DMEM over 6 years@Lucbug Thank you for sharing the link but unfortunately this article is not up to date and contains incorrect data. For example: it is saying: "iOS, for instance, will take a phone number after the sms: protocol, but will ignore everything – including the number – if body text is included" which is incorrect. Either way, the issue I asked about (SMS app must be opened in the background) is not even mentioned there as a problem.
-
Urosh T. over 6 years2017-11-17: Tried on Aquaris BQ, Nexus, iPhone 7 and LPhone and this works like a charm. Tried with various browsers (Chrome, Firefox, Opera, native). Thanks a lot!
-
Toskan over 6 yearsnone of the links seem to work with body in iOS 11.1
-
Konrad G over 5 yearsThat's the answer that I've been looking for. Thanks for the help!
-
kjr1995 over 5 yearsYou can get it to work by using <a href=sms:1234567890;?&body=https%3A%2F%2Fwww.google.com%2F>link</a>. I've tested it on android 8.0 and iOS 11.4.1.
-
morels over 5 yearsIt seems not true anymore according to stackoverflow.com/questions/39529099/…
-
Joshua Ohana over 5 yearsworks great but when done from OSX it opens up a text message To:
?
, any idea how to make it show up blank? I triedsms:?body
andsms:;?body
, the first tries to send to ? and the second tries to send to ; -
Ali over 5 years@JoshuaOhana What happens if you try "sms:?0123456789&body=My Message"? Sorry, don't have access to any Apple devices on hand.
-
Duke Dougal about 5 yearsApple has removed the ability to include body.
-
aslum about 5 yearsApparently Android has also removed the ability to include a body. I had this working and it stopped after the last android update. Sad.
-
Dan Parker about 5 yearsYes Android had made a change, see my longer response below but href="sms://15551235555?body=Hello" now seems to work for google message app
-
JCisar about 5 yearsDo you know if this works for all android or just certain versions? This is the version that worked for my Pixel 2, android 9
-
Dan Parker about 5 yearsI've had no problems with this on older androids I've tested as well.
-
JCisar about 5 yearsAlso, it does not seem to work when you do not provide a phone number (I know that's not part of the original question but it might be useful to know)
-
Silas S. Brown almost 5 yearsOn Android it depends on which SMS app is being used. For example, on Android 9 with the QKSMS app, this tries to send a message to ;? and the body is not included. (QKSMS is not the default app, but it may be in use by people who don't want the SMS to become an MMS after it reaches a certain size.) Unfortunately there is no way for the HTML page to determine which SMS app will be in use. For this reason I'm going to omit SMS links if I detect Android.
-
Ollie Khakwani over 4 yearsThanks for this, works great on iOS and Android! Watch out for the
Without Contact Number
version on MacOS - it sets the SMSto
to?
-
Michal about 4 yearsCan't create button without phone number.
-
Albert Renshaw about 4 yearsNew iOS one does work for me IFF the iMessage app was already running, but if it was launching fresh it just opens the app and doesn't create a new message. Android didn't work at all. Abandoning this feature in my web app for now
-
Doodlemeat almost 4 yearsDoesn't work for Android devices. Only a ?body= does the trick.
-
Dom Ramirez over 2 yearsYou crushed it here. Thanks for the modern era update. My HTML validator is giving me trouble with the ";?&" combo, which makes me think it might be problematic, but I have a short-term use case on my hands for now.
-
Vincent over 2 yearsIs it possible to populate iOS's optional subject field via sms?
-
Peter Knut about 2 yearsI've just tested one universal URL:
sms:18005555555?&body=Body
. Works on Android 10+, iOS 15, macOS 11.6+