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

HtmlIosHyperlinkSms

Html Problem Overview


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?

Html Solutions


Solution 1 - Html

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

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

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

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

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

Solution 6 - Html

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.

Solution 7 - Html

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.

Solution 8 - Html

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.

Solution 9 - Html

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>

Solution 10 - Html

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/

Solution 11 - Html

<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;
})

Solution 12 - Html

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.

Solution 13 - Html

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

Solution 14 - Html

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

This works on my iPhone 5S!

Solution 15 - Html

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;

Solution 16 - Html

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>

Solution 17 - Html

(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)

Solution 18 - Html

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

Solution 19 - Html

Used up to iOS 14, worked fine!

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

Solution 20 - Html

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>

Solution 21 - Html

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

Solution 22 - Html

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/

Solution 23 - Html

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];

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmerlincamView Question on Stackoverflow
Solution 1 - HtmlBrad OregoView Answer on Stackoverflow
Solution 2 - HtmlAliView Answer on Stackoverflow
Solution 3 - HtmllandenView Answer on Stackoverflow
Solution 4 - HtmlNathan SharfiView Answer on Stackoverflow
Solution 5 - HtmlaayushdroliaView Answer on Stackoverflow
Solution 6 - HtmlMahMoosView Answer on Stackoverflow
Solution 7 - HtmlBenView Answer on Stackoverflow
Solution 8 - HtmlDebbie VView Answer on Stackoverflow
Solution 9 - HtmlPankaj ChauhanView Answer on Stackoverflow
Solution 10 - HtmlSam CarltonView Answer on Stackoverflow
Solution 11 - HtmlhkongmView Answer on Stackoverflow
Solution 12 - HtmlRadley SustaireView Answer on Stackoverflow
Solution 13 - HtmlA. Z.View Answer on Stackoverflow
Solution 14 - HtmlKimView Answer on Stackoverflow
Solution 15 - HtmlLemon KaziView Answer on Stackoverflow
Solution 16 - HtmlDan ParkerView Answer on Stackoverflow
Solution 17 - Htmluser6200044View Answer on Stackoverflow
Solution 18 - HtmlNorthern CaptainView Answer on Stackoverflow
Solution 19 - HtmlAnil SinghView Answer on Stackoverflow
Solution 20 - HtmlpaaacmanView Answer on Stackoverflow
Solution 21 - HtmlGhigoView Answer on Stackoverflow
Solution 22 - HtmlJohn LauerView Answer on Stackoverflow
Solution 23 - HtmlIñigo BeitiaView Answer on Stackoverflow