Secure Login
VB

We offer code samples to make it easy for you to plug in SMS functionality into your applications.

Download our SDK containing sample projects in many languages or go straight to the language you need with our code samples.

Public Function SendMessage(username As String, password As String, destination As String, message As String)

Dim xmlstring As String

xmlstring = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?> " & _
"<Request xmlns:xsi=" & Chr(34) & "http://www.w3.org/2001/XMLSchema-instance" & Chr(34) & " xsi:noNamespaceSchemaLocation=" & Chr(34) & "http://schema.2sms.com/1.0/0410_RequestSendMessage.xsd" & Chr(34) & " Version = " & Chr(34) & "1.0" & Chr(34) & ">" & _
"<Identification>" & _
    "<UserID><![CDATA[" & username & "]]></UserID>" & _
    "<Password>" & password & "</Password>" & _
"</Identification>" & _
"<Service>" & _
    "<ServiceName>SendMessage</ServiceName>" & _
    "<ServiceDetail>" & _
        "<SingleMessage>" & _
            "<Destination>" & destination & "</Destination>" & _
            "<Text><![CDATA[" & message & "]]></Text>" & _
        "</SingleMessage>" & _
    "</ServiceDetail>" & _
"</Service>" & _
"</Request>"

'open connection to server and send

Dim xmlrequest As MSXML2.XMLHTTP
Set xmlrequest = New MSXML2.XMLHTTP

xmlrequest.Open "POST", "http://www.2sms.com/xml/xml.jsp", False

xmlrequest.setRequestHeader "content-type", "text/xml"
xmlrequest.send xmlstring

'get the response back

response = xmlrequest.responseText

'set up DOM to parse
Dim xmlresponse As MSXML2.DOMDocument30
Set xmlresponse = New MSXML2.DOMDocument

xmlresponse.async = False
xmlresponse.resolveExternals = False
xmlresponse.validateOnParse = False

On Error Resume Next

xmlresponse.loadXML response

'pull out relevant variables from response

javaresult = (xmlresponse.getElementsByTagName("Result").Item(0).Text)
errorCode = (xmlresponse.getElementsByTagName("ErrorCode").Item(0).Text)
errorreason = (xmlresponse.getElementsByTagName("ErrorReason").Item(0).Text)
messageid = (xmlresponse.getElementsByTagName("MessageID").Item(0).Text)

If errorCode = "00" Then

    SendMessage = javaresult
Else
    If errorreason = "" Then
        SendMessage = "Message Failed - Unknown Error"
    Else
        SendMessage = "Message FAILED. (Reason: " & errorreason & ")"
    End If
End If

End Function
©2sms Business Text Messaging,2018