Avatar billede pelskee Nybegynder
05. november 2003 - 15:32 Der er 5 kommentarer og
1 løsning

Nyhedsbrev fra database

jeg har lavet en side hvor jeg kan oprette et nyhedsbrev med overskrift, tekst og dato. indholdet af denne side skal skrives til databasen (det gør den nu), men den skal samtidigt tage indholdet og sætte det op og sende det til modtagerne af nyhedsbrevet som ligger i en anden tabel i databasen. Det ved jeg ikke hvordan man kan gøre - pls help

Opsætning på mailen skal være sådan her:
To:    <email> - alle fra DB, email adresserne skal ikke vises i send feltet
From:    Border-Wines
Re:    <Overskrift>

Body:
Hej <navn>

<Tekst>
Avatar billede dp2001 Juniormester
05. november 2003 - 15:54 #1
strSQL = "SELECT email FROM nyhedsbrev_modtager"
Set rs = Conn.Execute(strSQL)

Do Until rs.EOF

email = email & rs("email")

if Not rs.EOF then
  email = email & ";"
end if

rs.MoveNext
Loop
rs.Close


- derefter bruger du bare variablen email
Avatar billede pelskee Nybegynder
05. november 2003 - 16:05 #2
det fatter jeg intet af :)

skal jeg ikke lave en slags script der tager imod info fra min teksteditor til at skrive nyhedsbrevet i og kobler email + navn på og sender det ?

kode fra min opret nyhedsbrev side:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers=""
MM_authFailedURL="../login.asp"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
  If (true Or CStr(Session("MM_UserAuthorization"))="") Or _
        (InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
    MM_grantAccess = true
  End If
End If
If Not MM_grantAccess Then
  MM_qsChar = "?"
  If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
  MM_referrer = Request.ServerVariables("URL")
  if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
  MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
  Response.Redirect(MM_authFailedURL)
End If
%>
<!--#include file="../../Connections/scandlines.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "fHtmlEditor") Then

  MM_editConnection = MM_scandlines_STRING
  MM_editTable = "Nyhedsbreve"
  MM_editRedirectUrl = "oversigt_nyhedsbreve.asp"
  MM_fieldsStr  = "EditorValue|value|Overskrift|value|Dato|value"
  MM_columnsStr = "Tekst|',none,''|Overskrift|',none,''|Dato|',none,''"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")
 
  ' set the form values
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_formVal = MM_fields(MM_i+1)
    MM_typeArray = Split(MM_columns(MM_i+1),",")
    MM_delim = MM_typeArray(0)
    If (MM_delim = "none") Then MM_delim = ""
    MM_altVal = MM_typeArray(1)
    If (MM_altVal = "none") Then MM_altVal = ""
    MM_emptyVal = MM_typeArray(2)
    If (MM_emptyVal = "none") Then MM_emptyVal = ""
    If (MM_formVal = "") Then
      MM_formVal = MM_emptyVal
    Else
      If (MM_altVal <> "") Then
        MM_formVal = MM_altVal
      ElseIf (MM_delim = "'") Then  ' escape quotes
        MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
      Else
        MM_formVal = MM_delim + MM_formVal + MM_delim
      End If
    End If
    If (MM_i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End If
    MM_tableValues = MM_tableValues & MM_columns(MM_i)
    MM_dbValues = MM_dbValues & MM_formVal
  Next
  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

  If (Not MM_abortEdit) Then
    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>

<html>
<head>
<title>Content Management System</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../include/stylesheet.css" rel="stylesheet" type="text/css">
</head>
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<script language="JavaScript" src="../include/overlib.js"><!-- overLIB (c) Erik Bosrup --></script>
<body>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center" valign="top"><table width="760" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="110" height="110" style="border:1px solid #CCCCCC;"><!--#include virtual="admin/include/logo.asp" --></td>
                <td width="5">&nbsp;</td>
                <td style="border:1px solid #CCCCCC;"><!--#include virtual="admin/include/topmenu.asp" --></td>
              </tr>
            </table>
            <table width="100%" height="5" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td></td>
              </tr>
            </table>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="110" valign="top">
                  <!--#include virtual="admin/include/menu_nyhedsbrev.asp" -->
                </td>
                <td width="5">&nbsp;</td>
                <td align="center" valign="top" style="border:1px solid #CCCCCC;">
                  <style type="text/css">
<!--
.clsCursor {  cursor: hand}
-->
</style>
                  <script>
  initToolBar("foo");
  window.status  = "Current View: Wysiwyg";
</script>
                  <table width="95%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td><form ACTION="<%=MM_editAction%>" METHOD="POST" name="fHtmlEditor">

                          <textarea name="EditorValue" style="display: none;"></textarea>
                          <script language="JavaScript">

  var errorString = "Sorry but this web page needs\nWindows95 and Internet Explorer 5 or above to view."
  var Ok = "false";
  var name =  navigator.appName;
  var version =  parseFloat(navigator.appVersion);
  var platform = navigator.platform;

    if (platform == "Win32" && name == "Microsoft Internet Explorer" && version >= 4){
        Ok = "true";
    } else {
        Ok= "false";
    }

    if (Ok == "false") {
        alert(errorString);
    }

function ColorPalette_OnClick(colorString){
   
    cpick.bgColor=colorString;
    document.all.colourp.value=colorString;
    doFormat('ForeColor',colorString);
}

function initToolBar(ed) {
   
    var eb = document.all.editbar;
    if (ed!=null) {
        eb._editor = window.frames['myEditor'];
    }
}

function doFormat(what) {

    var eb = document.all.editbar;
       
    if(what == "FontName"){
        if(arguments[1] != 1){
            eb._editor.execCommand(what, arguments[1]);
            document.all.font.selectedIndex = 0;
        }
    } else if(what == "FontSize"){
    if(arguments[1] != 1){
      eb._editor.execCommand(what, arguments[1]);
      document.all.size.selectedIndex = 0;
    }
    } else {
      eb._editor.execCommand(what, arguments[1]);
    }
}

function swapMode() {

    var eb = document.all.editbar._editor;
  eb.swapModes();
}

function create() {

    var eb = document.all.editbar;
    eb._editor.newDocument();
}

function newFile(){

    create();
}

function makeUrl(){

    sUrl = document.all.what.value + document.all.url.value;
    doFormat('CreateLink',sUrl);
}

function copyValue() {

    var theHtml = "" + document.frames("myEditor").document.frames("textEdit").document.body.innerHTML + "";
    document.all.EditorValue.value = theHtml;
}

function SwapView_OnClick(){

  if(document.all.btnSwapView.value == "View Html"){
        var sMes = "View Wysiwyg";
    var sStatusBarMes = "Current View Html";
    } else {
        var sMes = "View Html"
    var sStatusBarMes = "Current View Wysiwyg";
  }
   
    document.all.btnSwapView.value = sMes;
  window.status  = sStatusBarMes;
    swapMode();
}

function Help_OnClick(){
  window.open("../../images/admin/editor_images/help_document.htm","wHelp", "toolbar=0, scrollbars=yes, width=640, height=480");
}

function OnFormSubmit(){

  if(confirm("Indholdet er ved at blive sendt til databasen\nEr du sikker på det er færdigt?")){
    copyValue();
    document.fHtmlEditor.submit();
  }
}
</script>
                          <br>
                          <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="150" class="12BlackBold">Opret nyhedsbrev</td>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <td width="150">&nbsp;</td>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <td class="10BlackNormal">Overskrift:</td>
                              <td><input name="Overskrift" type="text" class="fields" id="Overskrift"></td>
                            </tr>
                            <tr>
                              <td class="10BlackNormal">Dato:</td>
                              <td>
<input name="Dato" type="text" class="fields" id="Dato" value="<%= Date() %>">
                              </td>
                            </tr>
                            <tr>
                              <td class="10BlackNormal">&nbsp;</td>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <td width="150" class="10BlackNormal">Beskrivelse:</td>
                              <td>&nbsp;</td>
                            </tr>
                          </table>
                          <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td><table border="0" cellspacing="0" cellpadding="0" bgcolor="" width="100%" bordercolor="">
                                  <tr valign="top">
                                    <td> <table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
                                        <tr valign="top">
                                          <td valign="top"> <div id=editbar >
                                              <table width="100%" border="0" cellpadding="0" cellspacing="0" align="left">
                                                <tr>
                                                  <td> <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                      <tr>
                                                        <td> <table border="0">
                                                            <tr>
                                                              <td nowrap valign="baseline">
                                                                <div align="left">
                                                                  <img class='clsCursor' src="../../images/admin/editor_images/Bold.gif" width="16" height="16" border="0" align="absmiddle" alt="Fed" onClick="doFormat('Bold')">&nbsp
                                                                  <img class='clsCursor' src="../../images/admin/editor_images/Italics.gif" width="16" height="16" border="0" align="absmiddle" alt="Kursiv" onClick="doFormat('Italic')">&nbsp
                                                                  <img class='clsCursor' src="../../images/admin/editor_images/underline.gif" width="16" height="16" border="0" align="absmiddle" alt="Understregning" onClick="doFormat('Underline')" >&nbsp
                                                                  <img class='clsCursor' src="../../images/admin/editor_images/left.gif" width="16" height="16" border="0" alt="Venstrejusteret" align="absmiddle"  onClick="doFormat('JustifyLeft')">
                                                                  <img class='clsCursor' src="../../images/admin/editor_images/centre.gif" width="16" height="16" border="0" alt="Centreret" align="absmiddle" onClick="doFormat('JustifyCenter')">&nbsp
                                                                  <img class='clsCursor' src="../../images/admin/editor_images/right.gif" width="16" height="16" border="0" alt="Højrejusteret" align="absmiddle"  onClick="doFormat('JustifyRight')">&nbsp
                                                                </div></td>
                                                              <td valign="baseline" nowrap><img class='clsCursor' src="../../images/admin/editor_images/Cut.gif" width="16" height="16" border="0" alt="Klip" onClick="doFormat('Cut')">&nbsp
                                                                <img class='clsCursor' src="../../images/admin/editor_images/Copy.gif" width="16" height="16" border="0" alt="Kopier" onClick="doFormat('Copy')">&nbsp
                                                                <img class='clsCursor' src="../../images/admin/editor_images/Paste.gif" border="0" alt="Indsæt" onClick="doFormat('Paste')" width="16" height="16">&nbsp</td>
                                                              <td nowrap valign="baseline"><img class='clsCursor' src="../../images/admin/editor_images/para_bul.gif" width="16" height="16" border="0" alt="Opstilling med punktform" onClick="doFormat('InsertUnorderedList');" >&nbsp
                                                                <img class='clsCursor' src="../../images/admin/editor_images/para_num.gif" width="16" height="16" border="0" alt="Opstilling med nummer" onClick="doFormat('InsertOrderedList');" >&nbsp
                                                                <img class='clsCursor' src="../../images/admin/editor_images/indent.gif" width="20" height="16" alt="Formindsk indrykning" onClick="doFormat('Indent')">&nbsp
                                                                <img class='clsCursor' src="../../images/admin/editor_images/outdent.gif" width="20" height="16" alt="Forøg indrykning" onClick="doFormat('Outdent')">&nbsp
                                                                <img class='clsCursor' src="../../images/admin/editor_images/hr.gif" width="16" height="18" alt="Horisontal linie" onClick="doFormat('InsertHorizontalRule')"></td>
                                                              <td nowrap valign="baseline"><table border="0">
                                                                  <tr valign="baseline">
                                                                    <td nowrap>&nbsp;</td>
                                                                    <td nowrap>
                                                                      <select name="what" style="font: 8pt verdana;">
                                                                        <option value="http://" selected>http://</option>
                                                                        <option value="mailto:">mailto:</option>
                                                                        <option value="ftp://">ftp://</option>
                                                                        <option value="https://">https://</option>
                                                                      </select>
                                                                    </td>
                                                                    <td> <input type="text" name="url" size="35" class="fields">
                                                                    </td>
                                                                    <td> <input type="button" name="button2" value="Tilføj" onClick="makeUrl();" class="buttons">
                                                                    </td>
                                                                  </tr>
                                                                </table></td>
                                                            </tr>
                                                          </table></td>
                                                      </tr>
                                                    </table></td>
                                                </tr>
                                              </table>
                                            </div></td>
                                        </tr>
                                        <tr valign="top" align="left">
                                          <td valign="top"> <table width="100%" border="0" height="100%">
                                              <tr valign="top">
                                                <td width="100%" height="100%">
                                                  <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
                                                    <tr valign="top">
                                                      <td height="250" bgcolor="#FFFFFF">
                                                        <iframe id=myEditor src="../../images/admin/editor_images/pd_edit.htm" onfocus="initToolBar(this)" width=100% height=100%></iframe></td>
                                                    </tr>
                                                  </table></td>
                                                <!-- COLORPICKER_GOES_HERE -->
                                              </tr>
                                            </table></td>
                                        </tr>
                                      </table></td>
                                  </tr>
                                </table></td>
                            </tr>
                          </table>
                          <table width="100%" border="0" cellspacing="0" cellpadding="0">
                           
                            <tr>
                              <td width="150">&nbsp;</td>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <td width="150">&nbsp;</td>
                              <td align="right" class="10BlackNormal"><img class='clsCursor' src="../../images/admin/editor_images/save.jpg" width="24" height="24" border="0" alt="Gem" onClick="OnFormSubmit()";></td>
                            </tr>
                            <tr>
                              <td width="150">&nbsp;</td>
                              <td>&nbsp;</td>
                            </tr>
                          </table>
                       
                          <input type="hidden" name="MM_insert" value="fHtmlEditor">
                        </form></td>
                    </tr>
                  </table></td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
Avatar billede pelskee Nybegynder
07. november 2003 - 09:13 #3
okay - jeg har lavet dette script. hvordan ser det ud:

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../../Connections/scandlines.asp" -->
<%
Dim rsEmails
Dim rsEmails_numRows

Set rsEmails = Server.CreateObject("ADODB.Recordset")
rsEmails.ActiveConnection = MM_scandlines_STRING
rsEmails.Source = "SELECT * FROM Nyhedsbrev"
rsEmails.CursorType = 0
rsEmails.CursorLocation = 2
rsEmails.LockType = 1
rsEmails.Open()

rsEmails_numRows = 0
%>
<%
Do Until rs.EOF

email = email & rs("email")

if Not rs.EOF then
  email = email & ";"
end if

rs.MoveNext
Loop
rs.Close
%>
<%
Overskrift = Request.Form("Overskrift")
Tekst = Request.Form("EditorValue")

    Set JMail                 = Server.CreateObject("JMail.SMTPMail")
    JMail.ContentType        = "text/html"
    JMail.ServerAddress        = "websmtp.border-wines.dk"
    JMail.AddRecipient        email
    JMail.Sender            = "Border-Wines"
    JMail.Subject            = "Nyhedsbrev fra Border-Wines"
   
JMail.Body = "<font size='2' face='Verdana'>" &_
"<strong>" &_
Overskrift &_
"</strong>" &_
"<br>" &_
Tekst &_
"<br>" &_
"</font>"

    JMail.Priority = 3
    JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")
    JMail.Execute
    Response.Redirect "oversigt_nyhedsbrev.asp"

%>
<%
rsEmails.Close()
Set rsEmails = Nothing
%>

... jeg får fejl
Avatar billede pelskee Nybegynder
07. november 2003 - 10:15 #4
dette script virker - men den sender kun til den sidst oprettede Email:

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../../Connections/scandlines.asp" -->
<%
Dim rsNyhedsbrev
Dim rsNyhedsbrev_numRows

Set rsNyhedsbrev = Server.CreateObject("ADODB.Recordset")
rsNyhedsbrev.ActiveConnection = MM_scandlines_STRING
rsNyhedsbrev.Source = "SELECT * FROM Nyhedsbreve ORDER BY IDnyhedsbreve DESC"
rsNyhedsbrev.CursorType = 0
rsNyhedsbrev.CursorLocation = 2
rsNyhedsbrev.LockType = 1
rsNyhedsbrev.Open()

rsNyhedsbrev_numRows = 0
%>
<%
Dim rsEmails
Dim rsEmails_numRows

Set rsEmails = Server.CreateObject("ADODB.Recordset")
rsEmails.ActiveConnection = MM_scandlines_STRING
rsEmails.Source = "SELECT Email FROM Nyhedsbrev ORDER BY IDnyhedsbrev DESC"
rsEmails.CursorType = 0
rsEmails.CursorLocation = 2
rsEmails.LockType = 1
rsEmails.Open()

rsEmails_numRows = 0
%>
<%
Overskrift = (rsNyhedsbrev.Fields.Item("Overskrift").Value)
Tekst = (rsNyhedsbrev.Fields.Item("Tekst").Value)
Dato = (rsNyhedsbrev.Fields.Item("Dato").Value)
Mail = (rsEmails.Fields.Item("Email").Value)

    Set JMail                 = Server.CreateObject("JMail.SMTPMail")
    JMail.ContentType        = "text/html"
    JMail.ServerAddress        = "websmtp.border-wines.dk"
    JMail.AddRecipient        Mail
    JMail.Sender            = "Border-Wines"
    JMail.Subject            = "Nyhedsbrev fra Border-Wines"
   
JMail.Body = "<font size='2' face='Verdana'>" &_
"<strong>" &_
Overskrift &_
"</strong>" &_
"<br>" &_
"<br>" &_
Tekst &_
"<br>" &_
"</font>"

    JMail.Priority = 3
    JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")
    JMail.Execute
    Response.Redirect "http://www.fzy.dk"

%>
<%
rsNyhedsbrev.Close()
Set rsNyhedsbrev = Nothing
%>
<%
rsEmails.Close()
Set rsEmails = Nothing
%>
Avatar billede pelskee Nybegynder
07. november 2003 - 10:33 #5
jeg skal have det færdigt i dag -- sender 15 point din vej
Avatar billede pelskee Nybegynder
07. november 2003 - 10:33 #6
æv - du har ikke lagt noget svar... jeg lukker - sig til hvis du vil have point
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