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

25

151

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?

Ambroseambrosi answered 25/6, 2011 at 20:55 Comment(4)
I wonder if these QR scanners are opening the SMS app directly instead...Ambroseambrosi
I don't think it is possible. See these: #11348 #1517669Detest
this still true?No method?Immaculate
This is 100% possible. See my answer below for info.Lechery
L
216

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)

Lechery answered 1/10, 2013 at 21:32 Comment(28)
On iOS it looks like the format is: <a href="sms:[phone number];body=body text">Link</a>. Notice no square brackets on the body.Lamellate
Ah, 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 clearerLechery
Worked like a charm.Thank you so much for the live demonstration.+100Uam
seems to be working now. Hm weird. But cool that it's also possible for iOSSkirling
Note: 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.Lechery
I 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 :(Skirling
I 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)Scarlettscarp
The android one does not appear to work if your device opens to hangouts. It will pass in the phone number, but not the body.Bismuthic
For 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 &.Grugru
Big 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.Endoparasite
can I add new line char in the bodyAzerbaijan
@OrangeDog see my answer for iOS 7 #6480962Wales
@strikers I'm also having issue adding a new line character. Were you able to resolve that?Delve
This information i am searching for my project.Its very usefull for deeplink concepts in androidElkins
Do you know about windows phone?Scabrous
Is there any way to the cursor start in the position 0? I don't want it in the end of the body textClipclop
@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?Plasmo
Following on what @bfred.it said, the syntax even changes for different platforms. You can check the challenge section of this article.Zampino
@Zampino 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.Plasmo
none of the links seem to work with body in iOS 11.1Depilatory
You 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.Laborious
Apple has removed the ability to include body.Tsuda
Apparently Android has also removed the ability to include a body. I had this working and it stopped after the last android update. Sad.Rambler
Yes Android had made a change, see my longer response below but href="sms://15551235555?body=Hello" now seems to work for google message appCracking
New 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 nowFascia
@BradOrego, Can we pass any image inside the body content for SMS, I mean like a favicon icon or webpage logo with the SMS share to anyone, like the below screenshot screenrec.com/share/Qbgd9nDl8o,Ferriter
universal link <a href="sms://+123456789&?body=text &+?Wimbush
@Wimbush the "&" and "?" need swap position, like https://mcmap.net/q/87149/-how-to-pre-populate-the-sms-body-text-via-an-html-linkArdyth
H
73

I know this is an old thread but I stumbled upon it and found that some parts are no longer relevant.

I've found that if you want to just pre-populate the text without adding a phone number, you can do the following:

sms:?&body=/* message body here */
Heterolysis answered 26/1, 2016 at 12:31 Comment(5)
That's the answer that I've been looking for. Thanks for the help!Wimmer
works great but when done from OSX it opens up a text message To: ?, any idea how to make it show up blank? I tried sms:?body and sms:;?body, the first tries to send to ? and the second tries to send to ;Cryptograph
@JoshuaOhana What happens if you try "sms:?0123456789&body=My Message"? Sorry, don't have access to any Apple devices on hand.Heterolysis
Doesn't work for Android devices. Only a ?body= does the trick.Pooi
It works well for me on safari and chrome browser at my mobile device(android 13 and ios 16). But i found it works not well on my MIUI system browser, the sms body would be finally "=text" but not the right "text"Ardyth
F
41

For iOS 8, try this:

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

Switching the ";" with a "&" worked for me.

Fashionable answered 26/9, 2014 at 20:21 Comment(2)
fwiw I've just tested this on iOS 10 and it still works :).Con
@Fashionable 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?Plasmo
G
40

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>
Gleeful answered 1/8, 2016 at 21:3 Comment(3)
Just 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-populateTristich
2017-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!Hardboard
On 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.Harmaning
Z
33

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

Zeculon answered 17/5, 2018 at 11:53 Comment(1)
Thanks for this, works great on iOS and Android! Watch out for the Without Contact Number version on MacOS - it sets the SMS to to ?Antione
W
33

Android and iOS body only:

<a href="sms://;?&body=Hello%20World">Only body</a>

Android and iOS one recipient only with body:

<a href="sms://+15552345678;?&body=Hello%20World">one recipient only with body</a>

Only Android multiple recipients with body:

<a href="sms://+15552345678, +15552345679;?&body=Hello%20World">Android multiple recipients with body</a>

Only iOS multiple recipients with body:

<a href="sms://open?addresses=+15552345678,+15552345679;?&body=Hello%20World">iOS multiple recipients with body</a>

Note that the body should be URI encoded.

Wellfavored answered 27/9, 2019 at 9:36 Comment(4)
You 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.Matthaus
Is it possible to populate iOS's optional subject field via sms?Gree
Year 2022 href="sms:?&body=...." that worked for me for both IOS and AndroidMidway
Your solution is already included in the answer and it worked even before 2022. @MidwayWellfavored
L
11

We found a proposed method and tested:

<a href="sms:12345678?body=Hello my friend">Send SMS</a>

Here are the results:

  • iPhone4 - fault (empty body of message);
  • Nokia N8 - ok (body of message - "Hello my friend", To "12345678");
  • HTC Mozart - fault (message "unsupported page" (after click on the "Send sms" link));
  • HTC Desire - fault (message "Invalid recipients(s):
    <12345678?body=Hellomyfriend>"(after click on the "Send sms" link)).

I therefore conclude it doesn't really work - with this method at least.

Lisette answered 30/10, 2012 at 11:44 Comment(1)
For iPhone4, see my answer bellow #6480962Wales
B
10

For those wanting a solution that works in 2022 I set up a small web app that just uses the correct format for iOS, macOS, and Android automatically.

https://copy.gives/18005555555?body=Body+text+here

The issue in 2022 is that on iOS you * must * use double slashes as well as /&

So the respective working URLs are the following

sms://18005555555/&body=Body%20text%20here - iOS and macOS
sms://18005555555/?body=Body%20text%20here - Android

Notice the /& for Apple devices and /? for Android

You can try some working examples here(doesn't work embedded):

https://jsfiddle.net/thatguysam/swLtjh0q/

Bussard answered 21/12, 2021 at 19:29 Comment(3)
I've just tested one universal URL: sms:18005555555?&body=Body. Works on Android 10+, iOS 15, macOS 11.6+Sleuth
@SamCarlton, Can we pass any image inside the body content for SMS, I mean like a favicon icon or webpage logo with the SMS share to anyone, like the below screenshot screenrec.com/share/Qbgd9nDl8o,Ferriter
@NayanBaraiya I believe iOS doesn't allow embedding images via SMS URL; however, there are 2 alternatives you might try. 1 ) Set up a link with the image you want: raywenderlich.com/… 2 ) Use the Web Share API like so: codepen.io/ThatGuySam/pen/mdLQLRJ?editors=0010Bussard
E
6

To get sms: and mailto: links to work on both iPhone and Android, without any javascript, try this:

<a href="sms:321-555-1111?&body=This is what I want to sent">click to text</a>


<a href="mailto:[email protected]?&subject=My subject&body=This is what I want to sent">click to email</a>

I tested it on Chrome for Android & iPhone, and Safari on iPhone.
They all worked as expected. They worked without the phone number or email address as well.

Edmonton answered 24/8, 2017 at 16:19 Comment(0)
B
5

For using Android you use below code

<a href="sms:+32665?body=reg fb1>Send SMS</a>

For iOS you can use below code

<a href="sms:+32665&body=reg fb1>Send SMS</a>

below code working for both iOs and Android

<a href="sms:+32665?&body=reg fb1>Send SMS</a>
Brachycephalic answered 18/6, 2019 at 5:56 Comment(0)
H
4
<a href="###" data-telno="13800000000" data-smscontent="hello" class="XXXXX XXXXXX XXXXXX sendsms"/>

$('.sendsms').on('click', function(){
    var p = $(this).data('telno'),
        c = $(this).data('smscontent'),
        t = ';';

    if (!ios) { // add your own iOS check
        t = '?';
    }
    location.href = 'sms:'+ p + t + c;
})
Hagler answered 23/12, 2013 at 8:26 Comment(1)
Works on most android, and IOS 5 and 6. Does not work on IOS 7.Porch
B
4

Bradorego's solution is what worked for me, but here is a more expanded answer.

A small consideration is that you need to encode the body using %20 instead of +. For PHP, this means using rawurlencode($body) instead of urlencode($body). Otherwise you'll see plus signs in the message on old versions of iOS, instead of spaces.

Here is a jQuery function which will refit your SMS links for iOS devices. Android/other devices should work normally and won't execute the code.

HTML:

<a href="sms:+15551231234?body=Hello%20World">SMS "Hello World" to 555-123-1234</a>

jQuery:

(function() {
  if ( !navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ) return;

  jQuery('a[href^="sms:"]').attr('href', function() {
    // Convert: sms:+000?body=example
    // To iOS:  sms:+000;body=example (semicolon, not question mark)
    return jQuery(this).attr('href').replace(/sms:(\+?([0-9]*))?\?/, 'sms:$1;');
  });
})();

Consider using a class like a.sms-link instead of a[href^="sms:"] if possible.

Bondstone answered 12/2, 2015 at 19:40 Comment(0)
F
3

The iPhone doesn't accept any message text, it will only take in the phone number. You can see this here https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/SMSLinks/SMSLinks.html#//apple_ref/doc/uid/TP40007899-CH7-SW1

Ferraro answered 25/6, 2011 at 21:5 Comment(4)
this page is not accessible anymoreBumblebee
That'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.Grugru
Confirmed that iOS 10.2 doesn't support a "body" part as described in the link above.Gigahertz
It seems not true anymore according to #39529599Volsung
R
2
<a href="sms:/* phone number here */&body=/* body text here */">Link</a>

This works on my iPhone 5S!

Rhineland answered 19/2, 2015 at 18:57 Comment(0)
P
2

I suspect in most applications you won't know who to text, so you only want to fill the text body, not the number. That works as you'd expect by just leaving out the number - here's what the URLs look like in that case:

sms:?body=message

For iOS same thing except with the ;

sms:;body=message

Here's an example of the code I use to set up the SMS:

var ua = navigator.userAgent.toLowerCase();
var url;

if (ua.indexOf("iphone") > -1 || ua.indexOf("ipad") > -1)
   url = "sms:;body=" + encodeURIComponent("I'm at " + mapUrl + " @ " + pos.Address);
else
   url = "sms:?body=" + encodeURIComponent("I'm at " + mapUrl + " @ " + pos.Address);

   location.href = url;
Psychasthenia answered 26/8, 2016 at 11:17 Comment(0)
C
2

Well not only do you have to worry about iOS and Android, there's also which android messaging app. Google messaging app for Note 9 and some new galaxys do not open with text, but the samsung app works. The solution seems to be add // after the sms:

so sms://15551235555

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

should be

<a href="sms://15551235555?body=Hello">Link</a>
Cracking answered 21/3, 2019 at 18:20 Comment(3)
Do you know if this works for all android or just certain versions? This is the version that worked for my Pixel 2, android 9Ignore
I've had no problems with this on older androids I've tested as well.Cracking
Also, 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)Ignore
D
1

(Just a little bit of topic), but maybe if you searched you could stumble here... In markdown (tested with parsedown and on iOS / android) you could do :

   [Link](sms:phone_number,?&body=URL_encoded_body_text)
   //[send sms](sms:1234567890;?&body=my%20very%20interesting%20text)
Diacaustic answered 21/2, 2018 at 14:19 Comment(0)
B
1

Was struggling with ability to open SMS app with body only message, no recipients on iOS 11+.

None of the solutions above worked for me, it didn't open at all or opened with something pre-populated in recipients (like ';').

Finally I ended up with this syntax for body only:

sms:///?body=Hello%20World
Banville answered 30/3, 2021 at 18:9 Comment(0)
U
1

Used up to iOS 14, worked fine!

?body= //for Android
&body= //for iOS
Uniformitarian answered 2/7, 2021 at 8:43 Comment(0)
W
0

universal link use tel &? body

<a href="sms://+123456789&?body=url works on android and also ios">link ios+android</a>

https://output.jsbin.com/puqicel

link ios+android

<a href="sms://+123456789&?body=url works on android and also ios">link ios+android</a>
Wimbush answered 25/6, 2011 at 20:55 Comment(1)
This doesn't seem to work on MacOSImmovable
W
0

I found out that, on iPhone 4 with IOS 7, you CAN put a body to the SMS only if you set a phone number in the list of contact of the phone.

So the following will work If 0606060606 is part of my contacts:

<a href="sms:0606060606;body=Hello my friend">Send SMS</a>

By the way, on iOS 6 (iPhone 3GS), it's working with just a body :

<a href="sms:;body=Hello my friend">Send SMS</a>
Wales answered 31/10, 2015 at 11:48 Comment(0)
D
0

Every OS version has a different way of doing it. Take a look at the sms-link library

Devious answered 21/9, 2016 at 21:2 Comment(0)
G
0

Try smsto:12323232:test_msg. It should works on Iphone and Android.

Gennie answered 14/3, 2024 at 8:19 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Layoff
E
-1

One of the problems with a click-to-text link is solving the desktop scenario where no native texting app exists. A solution is to use Zipwhip's Click-to-Text button creator.

  • On the desktop, they send you an actual real text message behind the scenes from the user's input.
  • On iOS or Android you get the native texting functionality instead.

https://www.zipwhip.com/create-sms-button/

Excursive answered 27/5, 2017 at 17:12 Comment(1)
Can't create button without phone number.Statics
T
-4

Neither Android nor iPhones currently support the body copy element in a Tap to SMS hyperlink. It can be done programmatically though,

MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;

picker.recipients = [NSArray arrayWithObject:@"48151623"];  
picker.body = @"Body text.";

[self presentModalViewController:picker animated:YES];
[picker release];
Tantamount answered 25/6, 2011 at 21:7 Comment(2)
Is that Objective C? How do you call that from JavaScript or use it in HTML? Sounds impossible?Offal
Can 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.Lechery

© 2022 - 2025 — McMap. All rights reserved.