Avatar billede christian-s Nybegynder
04. november 2001 - 14:09 Der er 9 kommentarer og
3 løsninger

SMS sender - skal sende til personer fra en database

Jeg skal bruge et script der kan sende SMS ud til folk der her tilmeldt sig og oprettet i en SQL database.

Det skal helst være færdig kode, og et link til HELT færdig kode er også fint - hvis det er enkel kode.
Avatar billede malte Nybegynder
04. november 2001 - 14:53 #1
<%
    \' *******************************************************************************************
    \' * SMS Sender med mulighed for at dele beskeden op, hvis over 160 tegn.                    *
    \' *                                                                                            *
    \' * Xpt: 38893                                                                                *
    \' *******************************************************************************************
   
    \' *** SMTP Mail komponent valg ***
    \' 0 = JMail
    \' 1 = ASPMail
   
    intMailer = 0
    strSMTP = \"ditdomæne.dk\"        \' SMTP server
    strAfs = \"sms@ditdomæne.dk\"    \' En gyldig POP3 konto

    Function Wrap(ByVal Text, ByVal WrapChar, ByVal WrapAt)
        \' *****************************************************************************************************
        \' * WordWrap v1.2 - WordWraps a string off as near as possible to the specified max character amount  *
        \' * By Thomas Daugaard, December 11th, 2000.                                                              *
        \' *                                                                                                      *
        \' * Arguments: Text    : The string to wordwrap                                                      *
        \' *              WrapChar : A string specifying how/with what to wrap the string. Default is <br>          *
        \' *              WrapAt  : Numeric value specifying the maximum amount of characters allowed in a      *
        \' *                          string. Wraps backwards in the string to ensure that the max value is meet. *
        \' *                                                                                                      *
        \' *    Note: Arguments are passed By Value, not reference.                                                  *
        \' *****************************************************************************************************

        Text = Trim(Text)
        If Len(Text) =< WrapAt Or Len(Text) = 0 Or InStr(Text, \" \") = 0 Then Wrap = \"\" & Text: Exit Function
        If Len(WrapChar) = 0 Then WrapChar = \"<br>\"

        Do
            If Len(Text) < WrapAt Then strFinal = strFinal & Text: Exit Do
            strPart = Left(Text, WrapAt): intOff = WrapAt
            If Not Right(strPart, 1) = \" \" Then
                intOff = InStrRev(strPart, \" \")
                If intOff = 0 Then intOff = InStr(Text, WrapAt, \" \")
                If intOff = 0 Then strPart = Text
            End If
            strPart = Left(Text, intOff)
           
            Text = Right(Text, Len(Text) - Len(strPart))
            strFinal = strFinal & strPart & WrapChar
        Loop

        Wrap = strFinal
    End Function

    strNummer    = Request(\"nummer\")
    strFra        = Request(\"fra\")
    strBesked    = Request(\"besked\")

    If Len(strNummer) > 0 And Len(strFra) > 0 And Len(strBesked) > 0 Then

        strTeleDK = \"@sms.tdm.dk\"
        strSonofon = \"@note.sonofon.dk\"
        strTelia = \"@gsm1800.telia.dk\"
        strMobilix = \"@sms.orange.dk\"

        bolValid = False

        If Len(strNummer) = 8 And IsNumeric(strNummer) Then
            If CInt(Left(strNummer, 4)) > 2010 Then
                If CInt(Left(strNummer, 4)) => 2010 And CInt(Left(strNummer, 4)) =< 2059 Then strDom = strTeleDK
                If CInt(Left(strNummer, 4)) => 2060 And CInt(Left(strNummer, 4)) =< 2099 Then strDom = strSonofon
                If CInt(Left(strNummer, 4)) => 2110 And CInt(Left(strNummer, 4)) =< 2199 Then strDom = strTeleDK
                If CInt(Left(strNummer, 4)) => 2210 And CInt(Left(strNummer, 4)) =< 2299 Then strDom = strSonofon
                If CInt(Left(strNummer, 4)) => 2310 And CInt(Left(strNummer, 4)) =< 2399 Then strDom = strTeleDK
                If CInt(Left(strNummer, 4)) => 2610 And CInt(Left(strNummer, 4)) =< 2699 Then strDom = strMobilix
                If CInt(Left(strNummer, 4)) => 2710 And CInt(Left(strNummer, 4)) =< 2799 Then strDom = strMobilix
                If CInt(Left(strNummer, 4)) => 2810 And CInt(Left(strNummer, 4)) =< 2899 Then strDom = strTelia
                If CInt(Left(strNummer, 4)) => 3010 And CInt(Left(strNummer, 4)) =< 3689 Then strDom = strTeleDK
                If CInt(Left(strNummer, 4)) => 3690 And CInt(Left(strNummer, 4)) =< 3309 Then strDom = strMobilix
                If CInt(Left(strNummer, 4)) => 3810 And CInt(Left(strNummer, 4)) =< 4049 Then strDom = strTeleDK
                If CInt(Left(strNummer, 4)) => 4050 And CInt(Left(strNummer, 4)) =< 4099 Then strDom = strSonofon
                If CInt(Left(strNummer, 4)) => 4320 And CInt(Left(strNummer, 4)) =< 4679 Then strDom = strTeleDK
                If CInt(Left(strNummer, 4)) => 4690 And CInt(Left(strNummer, 4)) =< 4709 Then strDom = strMobilix
                If CInt(Left(strNummer, 4)) => 4710 And CInt(Left(strNummer, 4)) =< 4979 Then strDom = strTeleDK
                If CInt(Left(strNummer, 4)) =  6910 Or  CInt(Left(strNummer, 4)) =  6911 Then strDom = strMobilix
                If CInt(Left(strNummer, 4)) =  6912 Or  CInt(Left(strNummer, 4)) =  6966 Then strDom = strMobilix
                If CInt(Left(strNummer, 4)) => 6960 And CInt(Left(strNummer, 4)) =< 6964 Then strDom = strMobilix
                If CInt(Left(strNummer, 4)) =  6969 Or  CInt(Left(strNummer, 4)) =  6996 Then strDom = strMobilix
                If CInt(Left(strNummer, 4)) => 6980 And CInt(Left(strNummer, 4)) =< 6989 Then strDom = strMobilix

                If strDom > \"\" Then
                    strFra = \"(\" & strFra & \") \"
               
                    intSubtract = Len(strFra) + Len(srtAfs) + 24
                    intMsgSize = (160 - intSubtract)

                    If intMailer = 0 Then
                        Set JMail = Server.CreateObject(\"JMail.SMTPMail\")

                        JMail.ServerAddress = strSMTP
                        JMail.Sender = strAfs
                        JMail.AddRecipient (strNummer & strDom)
                    Else
                        Set ASPMail = Server.CreateObject(\"SMTPsvg.Mailer\")

                        ASPMail.RemoteHost = strSMTP
                        ASPMail.FromAddress = strAfs
                        ASPMail.AddRecipient \"\", (strNummer & strDom)
                    End If
               
                    If Len(strBesked) > intMsgSize then
                        strWrapped = Split(Wrap(strBesked, \"|\", intMsgSize), \"|\")
                       
                        For Index = 0 To UBound(strWrapped)
                            Select Case intMailer
                                Case 0: JMail.Body = strFra & strWrapped(Index):        JMail.Execute
                                Case 1: ASPMail.BodyText = strFra & strWrapped(Index):    ASPMail.SendMail
                            End Select
                        Next
                       
                        intMsgSize = UBound(strWrapped) + 1
                    Else
                        Select Case intMailer
                            Case 0: JMail.Body = strFra & strBesked:        JMail.Execute
                            Case 1: ASPMail.BodyText = strFra & strBesked:    ASPMail.SendMail
                        End Select
                       
                        intMsgSize = 1
                    End If
               
                    Set JMail = Nothing
               
                    bolValid = True
                    Select Case (intMsgSize > 1)
                        Case True:  strSendt = \"<font face=\'Tahoma\' size=2 color=#008000>Din besked blev sendt af <b>\" & intMsgSize & \"</b> SMS´er til <b>\" & strNummer & \"</b>.</font>\"
                        Case False: strSendt = \"<font face=\'Tahoma\' size=2 color=#008000>Din besked blev sendt til <b>\" & strNummer & \"</b>!</font>\"
                    End Select
                Else
                    strSendt = \"<font face=\'Tahoma\' size=2 color=#800000>Beskeden kunne ikke sendes da det indtastede tlf.<br>nummer ikke er et gyldigt mobil nummer!</font>\"
                End If
            End If
        End If
    End If
%>

    <script language=\"JavaScript\">
        <!--
            function showleft() {
                document.frmSms.count.value=800-(document.frmSms.besked.value.length+document.frmSms.fra.value.length);
            }
            function checklength() {
                if (document.frmSms.besked.value.length+document.frmSms.fra.value.length > 800) {
                    alert(\"Din besked må max. være på 800 tegn!\");
                    document.frmSms.besked.focus();
                    return (false);
                } else if (document.frmSms.nummer.value.length !=8) {
                    alert(\"Du skal skrive et gyldigt 8-cifret tlf. nummer!\");
                    document.frmSms.nummer.focus();
                    return (false);
                } else if (document.frmSms.fra.value.length == 0) {
                    alert(\"Du skal skrive et afsender navn/tlf. nummer!\");
                    document.frmSms.fra.focus();
                    return (false);
                }
               
                return (true)
            }
        -->
    </script>

<center>
    <form method=\"post\" action=\"sms.asp\" name=\"frmSms\" onsubmit=\"return checklength();\">
       
    <table border=0 cellspacing=0 cellpadding=5 bgcolor=#ffffff width=\"542\">
      <tr><td align=\"center\"><font face=\"Tahoma\" size=4><b>SendSMS</b></font></td></tr>
            <tr>
                <td>
                   
          <table border=0 width=100% cellspacing=0 cellpadding=0>
            <tr><td valign=\"top\" align=\"left\" colspan=4>&nbsp;</td></tr>
                        <tr>
                           
              <td valign=\"top\" align=\"left\" width=\"25%\">
                <p align=\"center\"><font face=\"Tahoma\" size=2>Tlf&nbsp;nummer:
                  modtager </font>
              </td>
                           
              <td valign=\"top\" align=\"left\" width=\"16%\">
                <input type=\"text\" name=\"nummer\" size=8 maxlength=8 style=\"font-family: tahoma; size: 8pt;\" value=\"<%=strNummer%>\"></td>
                           
              <td valign=\"top\" align=\"left\" width=\"30%\">
                <p align=\"center\"><font face=\"Tahoma\" size=2>Afsender: Navn eller
                  telefonnr. </font>
              </td>
                           
              <td valign=\"top\" align=\"left\" width=\"29%\">
                <input type=\"text\" name=\"fra\" size=10 style=\"font-family: tahoma; size: 8pt;\" onkeydown=\"showleft();\" value=\"<%=strFra%>\"></td>
                        </tr>
                        <tr>
                            <td valign=\"top\" align=\"center\" colspan=4>
                <textarea rows=5 name=\"besked\" border=0 onkeydown=\"showleft();\" style=\"font-family: tahoma; size: 8pt; width: 450px;\"><%=strBesked%></textarea>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td valign=\"top\" align=\"center\">
                    <input type=\"submit\" value=\"Send\" style=\"position: relative; left: 10px; top: -10px; font-family: tahoma; size: 8pt; color: #008000; font-weight: 700;\">
                    <input type=\"text\" name=\"count\" value=\"800\" style=\"position: relative; left: 111px; top: -10px; font-family: tahoma; size: 8pt; color: #000080; width: 28px;\" readonly>
                </tr>
            </table>
        <%=strSendt%>
    </form>
</center>
Avatar billede dumdum Nybegynder
04. november 2001 - 14:55 #2
60 point = svært spørgsmål


www.fotx.net/dumdum
Avatar billede somaliomar Praktikant
04. november 2001 - 14:56 #3
1. http://www.html.dk/scripts/asp/00004/
2. http://www.html.dk/scripts/asp/00010/
--------------------------------------
3. ConquerSMS 1.3 -  http://www.theill.com/files/conquersms.zip
Sends SMS to any mobile in Denmark. Source builds on AspMail or JMail (3.x/4.x) for sending out emails.
Avatar billede christian-s Nybegynder
04. november 2001 - 16:37 #4
Bliver telefonnumrene hentet fra en database i de scripts I har henvist til?
Avatar billede christian-s Nybegynder
04. november 2001 - 16:44 #5
dumdum: Du har jo helt ret, men desværre er ikke alle enige i det...
Avatar billede somaliomar Praktikant
04. november 2001 - 16:49 #6
christian-s >> Det kan det let gøres.

Du skal have installeret en eller anden mail-komponent(eks. ASPMail, JMail) på serveren!
Avatar billede malte Nybegynder
04. november 2001 - 16:54 #7
hvis i kombinerer scriptet med en mailliste vil den så ikke sende en sms istedet for en email??
Avatar billede christian-s Nybegynder
04. november 2001 - 17:33 #8
kunne I ikke sætte det SMS senderen sammen med en database, det er jo det i får pointene for :-)
Avatar billede eagleeye Praktikant
04. november 2001 - 19:30 #9
Jeg har taget maltes script og lavet det lidt om. Den hendter mobil numre fra en database. I databsen er en table som hedder tabel. Tabellen (tabel) har minimum 2 kolonner sms (tal;0:1) mobil (tekst)

Table:
sms : tal  ; 0 ingen sms besked tilsendt, 1 sms besked tilsendt
mobil : streng ; mobil nummer formatet sådan her  40404040.

Du skal rette database connectionen til så den passer med din database og rette SQL\'en til så den passer med din database..

Nede i sende functionen er der lige et par småting du skal rette for det passer med din side:
function SMSsender(strNummer, strFra, strBesked)
intMailer = 0  \'0=JMail komponent; 1=ASPmail komponent
strSMTP = \"ditdomæne.dk\" \' SMTP server rettes til
strAfs = \"sms@ditdomæne.dk\" \' En gyldig POP3 konto rettes til

Du skal også rette disse to tekst streng til:
strFra = \"ThisSite\"  \' Skal rettes til
strBesked = \"Denne smser rykker for vildt.\" \'Besked du vil sende


Her er koden så:

<html>
<head><title>SMS Sender</title></head>
<body>
<%
Set Conn = Server.CreateObject(\"ADODB.Connection\")
DataBase = \"Data Source=\"&Server.MapPath(\"db.mdb\")&\";Provider=Microsoft.Jet.OLEDB.4.0;\"
Conn.Open (DataBase)

strSQL = \"SELECT mobil FROM tabel WHERE sms = 1;\"
Set rs = Conn.Execute(strSQL)

strFra = \"ThisSite\"  \' Skal rette til FRA
strBesked = \"Denne smser rykker for vildt.\" \'Besked du vil sende

do while not rs.EOF
  Response.write SMSsender(rs(\"mobil\"),strFra,strBesked) & \"<br>\"
  rs.movenext
loop
conn.Close
set conn=nothing
%>
</body>
</html>
<%
Function Wrap(ByVal Text, ByVal WrapChar, ByVal WrapAt)
\' *****************************************************************************************************
\' * WordWrap v1.2 - WordWraps a string off as near as possible to the specified max character amount *
\' * By Thomas Daugaard, December 11th, 2000. *
\' * *
\' * Arguments: Text : The string to wordwrap *
\' * WrapChar : A string specifying how/with what to wrap the string. Default is <br> *
\' * WrapAt : Numeric value specifying the maximum amount of characters allowed in a *
\' * string. Wraps backwards in the string to ensure that the max value is meet. *
\' * *
\' * Note: Arguments are passed By Value, not reference. *
\' *****************************************************************************************************

Text = Trim(Text)
If Len(Text) =< WrapAt Or Len(Text) = 0 Or InStr(Text, \" \") = 0 Then Wrap = \"\" & Text: Exit Function
If Len(WrapChar) = 0 Then WrapChar = \"<br>\"
Do
  If Len(Text) < WrapAt Then strFinal = strFinal & Text: Exit Do
  strPart = Left(Text, WrapAt): intOff = WrapAt
  If Not Right(strPart, 1) = \" \" Then
    intOff = InStrRev(strPart, \" \")
    If intOff = 0 Then intOff = InStr(Text, WrapAt, \" \")
    If intOff = 0 Then strPart = Text
  End If
  strPart = Left(Text, intOff)
  Text = Right(Text, Len(Text) - Len(strPart))
  strFinal = strFinal & strPart & WrapChar
Loop
Wrap = strFinal
End Function

function SMSsender(strNummer, strFra, strBesked)
\' *** SMTP Mail komponent valg ***
\' 0 = JMail
\' 1 = ASPMail
intMailer = 0
strSMTP = \"ditdomæne.dk\" \' SMTP server rsttes til....
strAfs = \"sms@ditdomæne.dk\" \' En gyldig POP3 konto rettes til....

If Len(strNummer) > 0 And Len(strFra) > 0 And Len(strBesked) > 0 Then

  strTeleDK = \"@sms.tdm.dk\"
  strSonofon = \"@note.sonofon.dk\"
  strTelia = \"@gsm1800.telia.dk\"
  strMobilix = \"@sms.orange.dk\"

  bolValid = False

  If Len(strNummer) = 8 And IsNumeric(strNummer) Then
    If CInt(Left(strNummer, 4)) > 2010 Then
      If CInt(Left(strNummer, 4)) => 2010 And CInt(Left(strNummer, 4)) =< 2059 Then strDom = strTeleDK
      If CInt(Left(strNummer, 4)) => 2060 And CInt(Left(strNummer, 4)) =< 2099 Then strDom = strSonofon
      If CInt(Left(strNummer, 4)) => 2110 And CInt(Left(strNummer, 4)) =< 2199 Then strDom = strTeleDK
      If CInt(Left(strNummer, 4)) => 2210 And CInt(Left(strNummer, 4)) =< 2299 Then strDom = strSonofon
      If CInt(Left(strNummer, 4)) => 2310 And CInt(Left(strNummer, 4)) =< 2399 Then strDom = strTeleDK
      If CInt(Left(strNummer, 4)) => 2610 And CInt(Left(strNummer, 4)) =< 2699 Then strDom = strMobilix
      If CInt(Left(strNummer, 4)) => 2710 And CInt(Left(strNummer, 4)) =< 2799 Then strDom = strMobilix
      If CInt(Left(strNummer, 4)) => 2810 And CInt(Left(strNummer, 4)) =< 2899 Then strDom = strTelia
      If CInt(Left(strNummer, 4)) => 3010 And CInt(Left(strNummer, 4)) =< 3689 Then strDom = strTeleDK
      If CInt(Left(strNummer, 4)) => 3690 And CInt(Left(strNummer, 4)) =< 3309 Then strDom = strMobilix
      If CInt(Left(strNummer, 4)) => 3810 And CInt(Left(strNummer, 4)) =< 4049 Then strDom = strTeleDK
      If CInt(Left(strNummer, 4)) => 4050 And CInt(Left(strNummer, 4)) =< 4099 Then strDom = strSonofon
      If CInt(Left(strNummer, 4)) => 4320 And CInt(Left(strNummer, 4)) =< 4679 Then strDom = strTeleDK
      If CInt(Left(strNummer, 4)) => 4690 And CInt(Left(strNummer, 4)) =< 4709 Then strDom = strMobilix
      If CInt(Left(strNummer, 4)) => 4710 And CInt(Left(strNummer, 4)) =< 4979 Then strDom = strTeleDK
      If CInt(Left(strNummer, 4)) = 6910 Or CInt(Left(strNummer, 4)) = 6911 Then strDom = strMobilix
      If CInt(Left(strNummer, 4)) = 6912 Or CInt(Left(strNummer, 4)) = 6966 Then strDom = strMobilix
      If CInt(Left(strNummer, 4)) => 6960 And CInt(Left(strNummer, 4)) =< 6964 Then strDom = strMobilix
      If CInt(Left(strNummer, 4)) = 6969 Or CInt(Left(strNummer, 4)) = 6996 Then strDom = strMobilix
      If CInt(Left(strNummer, 4)) => 6980 And CInt(Left(strNummer, 4)) =< 6989 Then strDom = strMobilix

      If strDom > \"\" Then
        strFra = \"(\" & strFra & \") \"

        intSubtract = Len(strFra) + Len(srtAfs) + 24
        intMsgSize = (160 - intSubtract)

        If intMailer = 0 Then
          Set JMail = Server.CreateObject(\"JMail.SMTPMail\")
          JMail.ServerAddress = strSMTP
          JMail.Sender = strAfs
          JMail.AddRecipient (strNummer & strDom)
        Else
          Set ASPMail = Server.CreateObject(\"SMTPsvg.Mailer\")
          ASPMail.RemoteHost = strSMTP
          ASPMail.FromAddress = strAfs
          ASPMail.AddRecipient \"\", (strNummer & strDom)
        End If

        If Len(strBesked) > intMsgSize then
          strWrapped = Split(Wrap(strBesked, \"|\", intMsgSize), \"|\")
          For Index = 0 To UBound(strWrapped)
            Select Case intMailer
              Case 0: JMail.Body = strFra & strWrapped(Index): JMail.Execute
              Case 1: ASPMail.BodyText = strFra & strWrapped(Index): ASPMail.SendMail
            End Select
          Next
          intMsgSize = UBound(strWrapped) + 1
        Else
          Select Case intMailer
            Case 0: JMail.Body = strFra & strBesked: JMail.Execute
            Case 1: ASPMail.BodyText = strFra & strBesked: ASPMail.SendMail
          End Select
          intMsgSize = 1
        End If

        Set JMail = Nothing

        bolValid = True
        Select Case (intMsgSize > 1)
          Case True: strSendt = \"Din besked blev sendt af <b>\" & intMsgSize & \"</b> SMS´er til <b>\" & strNummer & \"</b>.\"
          Case False: strSendt = \"Din besked blev sendt til <b>\" & strNummer & \"</b>.\"
        End Select
      Else
        strSendt = \"Beskeden kunne ikke sendes da det indtastede tlf nummer ikke er et gyldigt mobil nummer, <b>\" & strNummer & \"</b>.\"
      End If
    Else
      strSendt = \"Beskeden kunne ikke sendes da det indtastede tlf nummer ikke er et gyldigt mobil nummer, <b>\" & strNummer & \"</b>.\"
    End If
  Else
    strSendt = \"Beskeden kunne ikke sendes da det indtastede tlf nummer ikke er et gyldigt mobil nummer, <b>\" & strNummer & \"</b>.\"
  End If
Else
  strSendt = \"Fejl i besked, fra eller mobil nummer!\"
End If
SMSsender = strSendt
end function
%>
Avatar billede christian-s Nybegynder
04. november 2001 - 20:08 #10
eagleeye:
Det lyder rigtig godt, men jeg forstår ikke helt det du skriver med tabellerne - hvad er hvad?

\"2 kolonner sms (tal;0:1) mobil (tekst)\"
Avatar billede eagleeye Praktikant
04. november 2001 - 21:50 #11
Jeg har lavet en SQL som hendte dem mobil numre ud som skal sendes til:

strSQL = \"SELECT mobil FROM tabel WHERE sms = 1;\"

sms skal være defineret som tal i databasen.
0 = ingen SMS besked ønskes
1 = SMS besked ønskes

Mobil skal være defineret som tekst(streng) i databasen.
Mobil indeholder mobil nummere som SMS\'en skal sendes til.
Avatar billede christian-s Nybegynder
04. november 2001 - 22:03 #12
okay mange tak, jeg vil lige prøve at sende det til en der skal teste det på sin NT server - så vender jeg tilbage!
du må bære lidt over med \"ventetiden\" :)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester