Monday, November 24, 2008

Sending an SMS from a mobile web site

One can send an SMS (Short Message System) from a mobile website by using the following syntax:

<a href="smsto:00441234567?body=This is a great blog http://jackdevofalltrades.blogspot.com">Send SMS</a>

So far so good, the problem I encountered is that on some mobiles the editor opens but the message is not displayed in the editor.
I encountered this issue on some Sony Ericsson mobiles, in particular mobiles on the HB107 platform.

The Href needs to be encoded to a "encoded word" with character set, according to RFC 2047 (ftp://ftp.rfc-editor.org/in-notes/rfc2047.txt) in this form:

=?iso-8859-1?q?here goes the message?=

Additionally, some characters must be Quoted Printable encoded. For example, blanks are replaced by "=20", and equal sign "=" is replaced by "=3D".

This result the original message into the following:
=?iso-8859-1?q?This=20is=20a=20great=20blog=20http://jackdevofalltrades.blogspot.com?=
For the Quoted Printable encoding I found a little utility class which did the job.

Finally, the string need to be URL encoded so it is treated as one body parameter inside the smsto link.
"=" is replaced by "%3D", "?" is replaced by "%3F" etc.

No comments:

Post a Comment