asked on
Public Function sendSMS(strApiKey As String, strApiSecret As String, strTarget As String, strText As String) As String
strFrom = "myFib"
Dim strPostURL As String
Dim arrResponse
Dim objRequest As New MSXML2.XMLHTTP
Dim strAnswer As String
strPostURL = "https://rest.nexmo.com/sms/json"
strPostURL = strPostURL & "?api_key="
strPostURL = strPostURL & strApiKey
strPostURL = strPostURL & "&api_secret=" & strApiSecret
strPostURL = strPostURL & "&from=" & "myFM"
strPostURL = strPostURL & "&type=unicode"
strPostURL = strPostURL & "&to=" & strTarget
strPostURL = strPostURL & "&text=" & strText
MsgBox strPostURL
On Error GoTo Error_Handler
' Default to false in case anything goes wrong.
sendSMS = ""
' We use xmlHTTP to submit the input values and record the response
objRequest.Open "POST", strPostURL, False
objRequest.Send
arrResponse = objRequest.responseText
sendSMS = arrResponse
Exit Function
Exit_Handler:
On Error Resume Next
Set objRequest = Nothing
Exit Function
Error_Handler:
MsgBox Err.Description, _
"ERROR " & Err.Number
Resume Exit_Handler
End Function