145

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
merlincam
  • 1,818
  • 3
  • 16
  • 16

24 Answers24

210

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)

Brad Orego
  • 2,976
  • 3
  • 18
  • 24
  • On iOS it looks like the format is: Link. Notice no square brackets on the body. – Rick Strahl Oct 09 '13 at 04:21
  • 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 clearer – Brad Orego Nov 11 '13 at 16:15
  • Worked like a charm.Thank you so much for the live demonstration.+100 – Harikrishnan Nov 26 '13 at 05:28
  • seems to be working now. Hm weird. But cool that it's also possible for iOS – MMachinegun Jan 24 '14 at 16:16
  • 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 '14 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 :( – MMachinegun Jan 24 '14 at 17:36
  • 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) – Uirri May 27 '14 at 09:10
  • 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. – jefeman Feb 11 '15 at 17:47
  • For those still looking, it turns out with iOS 8 the syntax changed to Link, where [phone number] is optional. TL;DR: iOS change ; to &. – Greg Johnson Mar 13 '15 at 19:04
  • 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 04 '15 at 22:16
  • can I add new line char in the body – Strikers Oct 10 '15 at 11:42
  • 1
    @OrangeDog see my answer for iOS 7 http://stackoverflow.com/questions/6480462/how-to-pre-populate-the-sms-body-text-via-an-html-link/33451189#answer-33451189 – paaacman Oct 31 '15 at 15:44
  • @strikers I'm also having issue adding a new line character. Were you able to resolve that? – Manish Ahuja Feb 23 '16 at 08:01
  • This information i am searching for my project.Its very usefull for deeplink concepts in android – SIVAKUMAR.J Apr 19 '16 at 09:22
  • Do you know about windows phone? – Bidstrup Jun 09 '16 at 12:27
  • Is there any way to the cursor start in the position 0? I don't want it in the end of the body text – Bruno Lemos Jun 17 '17 at 05:38
  • @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 Oct 18 '17 at 19:40
  • Following on what @bfred.it said, the syntax even changes for different platforms. You can check the challenge section of [this article](http://thenewcode.com/856/Send-a-SMS-Text-From-A-Link). – Lucbug Oct 19 '17 at 09:13
  • @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. – DMEM Oct 20 '17 at 13:39
  • 2
    none of the links seem to work with body in iOS 11.1 – Toskan Jan 30 '18 at 21:58
  • 1
    You can get it to work by using link. I've tested it on android 8.0 and iOS 11.4.1. – kjr1995 Sep 19 '18 at 15:23
  • Apple has removed the ability to include body. – Duke Dougal Mar 17 '19 at 01:31
  • 1
    Apparently Android has also removed the ability to include a body. I had this working and it stopped after the last android update. Sad. – aslum Mar 21 '19 at 16:36
  • Yes Android had made a change, see my longer response below but href="sms://15551235555?body=Hello" now seems to work for google message app – Dan Parker Mar 21 '19 at 18:32
  • 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 now – Albert Renshaw May 06 '20 at 03:38
  • @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 https://screenrec.com/share/Qbgd9nDl8o, – Rik Patel Oct 10 '22 at 06:40
  • universal link – Shkur Jan 31 '23 at 20:55
70

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 */
Ali
  • 837
  • 8
  • 9
  • 2
    That's the answer that I've been looking for. Thanks for the help! – Konrad G Sep 14 '18 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 ; – Joshua Ohana Jan 21 '19 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 '19 at 06:35
  • 2
    Doesn't work for Android devices. Only a ?body= does the trick. – Doodlemeat Jul 07 '20 at 09:50
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.

landen
  • 411
  • 4
  • 2
  • 3
    fwiw I've just tested this on iOS 10 and it still works :). – Rob Dawson Oct 14 '16 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 '17 at 19:43
38

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>
hcarrasko
  • 2,320
  • 6
  • 33
  • 45
Nathan Sharfi
  • 389
  • 3
  • 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 06 '17 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 '17 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. – Silas S. Brown May 14 '19 at 15:34
31

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

aayushdrolia
  • 411
  • 4
  • 3
  • 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 `?` – Ollie Khakwani Dec 04 '19 at 18:57
26

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.

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

Ben
  • 1,631
  • 13
  • 15
  • For iPhone4, see my answer bellow http://stackoverflow.com/questions/6480462/how-to-pre-populate-the-sms-body-text-via-an-html-link/33451189#answer-33451189 – paaacman Oct 31 '15 at 15:45
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/

Sam Carlton
  • 1,190
  • 1
  • 17
  • 18
  • 2
    I've just tested one universal URL: `sms:18005555555?&body=Body`. Works on Android 10+, iOS 15, macOS 11.6+ – Peter Knut Apr 28 '22 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 https://screenrec.com/share/Qbgd9nDl8o, – Rik Patel Oct 10 '22 at 06: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: https://www.raywenderlich.com/7565482-visually-rich-links-tutorial-for-ios-image-thumbnails 2 ) Use the Web Share API like so: https://codepen.io/ThatGuySam/pen/mdLQLRJ?editors=0010 – Sam Carlton Oct 10 '22 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:someone@sample.com?&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.

Debbie V
  • 314
  • 3
  • 5
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>
Pankaj Chauhan
  • 1,623
  • 14
  • 12
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;
})
Tino
  • 106
  • 6
hkongm
  • 59
  • 3
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.

Radley Sustaire
  • 3,382
  • 9
  • 37
  • 48
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

Luciano
  • 1,101
  • 1
  • 19
  • 30
A. Z.
  • 198
  • 1
  • 9
  • 1
    this page is not accessible anymore – Kirk Hammett Mar 17 '14 at 16:40
  • 1
    That's no longer true with iOS8. You can send Link - the ampersand precedes the body=. Syntactically confusing, yes, but it's working for me and the body populates with the desired message. – Greg Johnson Mar 13 '15 at 19:06
  • 1
    Confirmed that iOS 10.2 doesn't support a "body" part as described in the link above. – Nicodemuz Jan 02 '17 at 01:50
  • It seems not true anymore according to https://stackoverflow.com/questions/39529099/trying-to-send-sms-in-ios-10-is-sms-protocol-broken#answer-39572784 – morels Sep 21 '18 at 16:30
2
<a href="sms:/* phone number here */&body=/* body text here */">Link</a>

This works on my iPhone 5S!

Kim
  • 41
  • 3
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;
Lemon Kazi
  • 3,308
  • 2
  • 37
  • 67
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>
Dan Parker
  • 823
  • 1
  • 11
  • 27
  • 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 '19 at 01:25
  • I've had no problems with this on older androids I've tested as well. – Dan Parker Apr 17 '19 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 '19 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
Northern Captain
  • 1,147
  • 3
  • 25
  • 32
1

Used up to iOS 14, worked fine!

?body= //for Android
&body= //for iOS
Anil Singh
  • 4,293
  • 2
  • 24
  • 19
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>
Shkur
  • 379
  • 3
  • 10
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>
paaacman
  • 3,012
  • 1
  • 20
  • 18
0

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

Ghigo
  • 1,657
  • 1
  • 13
  • 18
-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/

-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];
Iñigo Beitia
  • 6,303
  • 4
  • 40
  • 46
  • Is that Objective C? How do you call that from JavaScript or use it in HTML? Sounds impossible? – sparkyspider Apr 13 '12 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 '13 at 18:46