How can I create a website button to send SMS to a phone number?

I found solutions that make it so that when you click a button on a website, it refers to a phone number, and a user phone opens a dialer with the amount that was pre-filled so.

Instead, I want to open the sms user application in "compose message" mode for this particular number. Is there any way to do this? I tried the following approach, but it does not work on Android:

sms://1-516-400-6217
+7
source share
2 answers

General format: <a href="sms:+919999999999?body=Hello World!">Link</a>

You can also add several numbers to the recipient list:
<a href="sms:+919999999999,+919999999990?body=Hello World!">Link</a>

I found that this works on my Android device as well:
<a href="sms://+919999999999?body=Hello%20World!">Single recipient and encoded body</a>

A small demonstration:

body {
  font-family: monospace;
  text-align: center;
}

a {
  font-size: 24px;
}

code {
  font-size: 18px;
  line-height: 26px;
  white-space: normal;
  word-break: break-word;
  background-color: lightgray;
  padding: 5px;
  border-radius: 4px;
}

h1 {
  margin-bottom: 5%;
}
<!DOCTYPE html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
  <h1> Run this Snippet on an actual mobile device to check if it supports the special links</h1>
  <hr>

  <pre><code>&lt;a href=&quot;sms:+919999999999?body=Hello World!&quot;&gt;Single recipient and plain body&lt;/a&gt;</code></pre>
  <a href="sms:+919999999999?body=Hello World!">Single recipient and plain body</a>

  <pre>
<br>
</pre>


  <pre><code>&lt;a href=&quot;sms:+919999999999,+919999999990?body=Hello World!&quot;&gt;Multile recipient and plain body&lt;/a&gt;</code></pre>
  <a href="sms:+919999999999,+919999999990?body=Hello World!">Multile recipient and plain body</a>

  <pre>
<br>
</pre>


  <pre><code>&lt;a href=&quot;sms://+919999999999?body=Hello%20World!&quot;&gt;Single recipient and encoded body&lt;/a&gt;</code></pre>
  <a href="sms://+919999999999?body=Hello%20World!">Single recipient and encoded body</a>
</body>
Run codeHide result

: SMS-

, SMS, , .

, ; .

+14

@, , , ?

0

Source: https://habr.com/ru/post/1589087/


All Articles