148

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?

4

24 Answers 24

214

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)

28
  • 5
    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.
    – Brad Orego
    Jan 24, 2014 at 17:04
  • 3
    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 :( Jan 24, 2014 at 17:36
  • 9
    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.
    – fregante
    Aug 4, 2015 at 22:16
  • 1
    @OrangeDog see my answer for iOS 7 stackoverflow.com/questions/6480462/…
    – paaacman
    Oct 31, 2015 at 15:44
  • 2
    none of the links seem to work with body in iOS 11.1
    – Toskan
    Jan 30, 2018 at 21:58
73

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 */
5
  • 2
    That's the answer that I've been looking for. Thanks for the help!
    – Konrad G
    Sep 14, 2018 at 14:57
  • 1
    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 ; Jan 21, 2019 at 16:42
  • @JoshuaOhana What happens if you try "sms:?0123456789&body=My Message"? Sorry, don't have access to any Apple devices on hand.
    – Ali
    Jan 23, 2019 at 6:35
  • 3
    Doesn't work for Android devices. Only a ?body= does the trick.
    – Doodlemeat
    Jul 7, 2020 at 9:50
  • 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" Oct 17 at 8:22
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.

2
  • 3
    fwiw I've just tested this on iOS 10 and it still works :).
    – Rob Dawson
    Oct 14, 2016 at 22:16
  • @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?
    – DMEM
    Oct 18, 2017 at 19:43
39

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>
3
  • 1
    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-populate
    – ibex
    Jul 6, 2017 at 21:12
  • 1
    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!
    – Urosh T.
    Nov 17, 2017 at 10:43
  • 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. May 14, 2019 at 15:34
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

1
  • 2
    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 ? Dec 4, 2019 at 18:57
29

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.

4
  • 1
    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. Sep 9, 2021 at 5:09
  • Is it possible to populate iOS's optional subject field via sms?
    – Vincent
    Sep 18, 2021 at 7:48
  • 1
    Year 2022 href="sms:?&body=...." that worked for me for both IOS and Android Sep 30, 2022 at 19:21
  • Your solution is already included in the answer and it worked even before 2022. @AwesomeUserName
    – MahMoos
    Oct 1, 2022 at 10:47
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.

1
9

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/

3
  • 3
    I've just tested one universal URL: sms:18005555555?&body=Body. Works on Android 10+, iOS 15, macOS 11.6+
    – Peter Knut
    Apr 28, 2022 at 13:37
  • 1
    @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,
    – Rik Patel
    Oct 10, 2022 at 6:39
  • @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=0010 Oct 10, 2022 at 20:50
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.

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>
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.

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;
})
1
  • 1
    Works on most android, and IOS 5 and 6. Does not work on IOS 7.
    – David C
    Mar 6, 2014 at 16:24
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

4
  • 1
    this page is not accessible anymore Mar 17, 2014 at 16:40
  • 1
    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. Mar 13, 2015 at 19:06
  • 1
    Confirmed that iOS 10.2 doesn't support a "body" part as described in the link above.
    – Nicodemuz
    Jan 2, 2017 at 1:50
  • It seems not true anymore according to stackoverflow.com/questions/39529099/…
    – morels
    Sep 21, 2018 at 16:30
2
<a href="sms:/* phone number here */&body=/* body text here */">Link</a>

This works on my iPhone 5S!

0
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;
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>
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 9
    – JCisar
    Apr 17, 2019 at 1:25
  • I've had no problems with this on older androids I've tested as well.
    – Dan Parker
    Apr 17, 2019 at 22:42
  • 2
    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)
    – JCisar
    Apr 23, 2019 at 21:35
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)
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
1

Used up to iOS 14, worked fine!

?body= //for Android
&body= //for iOS
1

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>

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>
0

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

-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/

1
  • Can't create button without phone number.
    – Michal
    Apr 1, 2020 at 11:11
-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];
2
  • Is that Objective C? How do you call that from JavaScript or use it in HTML? Sounds impossible? Apr 13, 2012 at 11:37
  • 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.
    – Brad Orego
    Dec 23, 2013 at 18:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.