How to pre-fill sms body text via html link

How to use html link to open sms application with pre-filled body?

All that I read seems to indicate that sms: 18005555555? body = bodyTextHere

It should work, but on the iPhone it does not work. Should I choose a body? Body = bodyTextHere and just use sms: phonenumber, it works.

I saw several examples where QR codes do this through a safari link. How can they pre-fill body text?

+101
html ios hyperlink sms
Jun 25 2018-11-11T00:
source share
19 answers

It turns out that this is 100% possible, although a bit hacked.

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 the following:

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

Live demo here: http://bradorego.com/test/sms.html (note that "Phone and" body "and" Phone and body "should autocomplete as a field: and body text. View source for additional information)

UPDATE:

Obviously, iOS8 had to go and change things for us, so thanks to some other commentators / respondents, a new style for iOS appeared:

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

(phone number is optional)

+162
Oct 01 '13 at 21:32
source share

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

I found that if you just want to fill in the text without adding a phone number, you can do the following:

 sms:?&body=/* message body here */ 
+44
Jan 26 '16 at 12:31 on
source share

For iOS 8, try the following:

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

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

+39
Sep 26 '14 at 20:21
source share

Just put all the characters in this order (I tested it only in this order, as it makes the most reasonable code for me).

Notification for body link ... I just put ... ;?&body= . Also note that I found that I need to use %20 for any spaces.

I tested it on my iphone (v. 9.2) and another Android, and it works fine.

This will solve the problem of having to crack it for different devices. I have no artifacts when I tested it in 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> 
+30
Aug 01 '16 at 21:03
source share

There is no 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

+12
May 17 '18 at 11:53
source share

We found the proposed method and tested:

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

Here are the results:

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

Therefore, I conclude that this really does not work - at least with this method.

+10
Oct 30 '12 at 11:44
source share

To get sms: and mailto: links to work on iPhone and Android, without javascript, try the following:

 <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 and iPhone and Safari on iPhone.
They all worked as expected. They worked without a phone number or email address.

+5
Aug 24 '17 at 16:19
source share
 <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; }) 
+4
Dec 23 '13 at 8:26
source share

Bradorego's solution is what worked for me, but here is a more extended 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 will see the plus signs in the message in older versions of iOS instead of spaces.

Here is a jQuery function that will update your SMS links for iOS devices. Android / other devices should work fine and will not execute 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;'); }); })(); 

If possible, use a[href^="sms:"] class, for example a.sms-link , instead of a[href^="sms:"] .

+4
Feb 12 '15 at 19:40
source share
+3
Jun 25 2018-11-11T00:
source share

Well, you need to not only worry about iOS and Android, but also about which messaging app for Android. The Google messaging app for Note 9 and some new galaxies does not open with text, but the Samsung app works. The solution seems to add // after 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> 
+2
Mar 21 '19 at 18:20
source share
 <a href="sms:/* phone number here */&body=/* body text here */">Link</a> 

It works on my iPhone 5S!

+1
Feb 19 '15 at 18:57
source share

I suspect that in most applications you do not know who to write to, so you only want to fill in the text, not the number. This works the way you expected, just leaving the number - this is what the URLs look like in this case:

 sms:?body=message 

For iOS, the same thing except:

 sms:;body=message 

Here is an example of the code that I use to configure 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; 
+1
Aug 26 '16 at 11:17
source share

(A bit of a topic), but maybe if you were looking, 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
Feb 21
source share

To use Android you use the code below

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

For iOS, you can use the code below

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

the code below works for both iOS and Android

 <a href="sms:+32665?&body=reg fb1>Send SMS</a> 
+1
Jun 18 '19 at 5:56 on
source share

I found out that on iPhone 4 with iOS 7 you can only put a body in SMS if you set the phone number in the phone’s contact list.

So, the following will work: 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 only works with the body:

 <a href="sms:;body=Hello my friend">Send SMS</a> 
0
Oct 31 '15 at 11:48
source share

Each OS version has a different way to do this. Take a look at sms-link library

0
Sep 21 '16 at 21:02
source share

One of the problems with the click to text link is to solve a desktop script where there is no native text messaging application. The solution is to use the creator of the Zipwhip Click-to-Text button.

  • On the desktop, they send you a real text message overs from user input.
  • On iOS or Android, you get built-in text functionality.

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

0
May 27 '17 at 17:12
source share

Neither Android nor iPhone currently support the body copy element in the Tap to SMS hyperlink. This can be done programmatically, but

 MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init]; picker.messageComposeDelegate = self; picker.recipients = [NSArray arrayWithObject:@"48151623"]; picker.body = @"Body text."; [self presentModalViewController:picker animated:YES]; [picker release]; 
-3
Jun 25 2018-11-11T00:
source share



All Articles