---
title: "problem med cdonts"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/86760-problem-med-cdonts"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "mackanz"
published: "2003-09-23T08:09:28.000Z"
updated: "2003-09-25T10:11:26.000Z"
replies: 18
views: 738
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/86760-problem-med-cdonts"
---

# problem med cdonts

## #1 — mackanz, 2003-09-23T08:09Z

Jag har ett litet problem med cdonts. 
Här nedan är ett exempel från <https://www.asp-sidan.nu>

\<%
' kolla om vi ska skicka iväg ett e-mail
If Len(Request.Form("email")) \> 0 AND Len(Request.Form("subject")) \> 0 AND Len(Request.Form("message")) \> 0 Then 
Set newMail = CreateObject("CDONTS.NewMail")
newMail.From = Request.Form("email")
newMail.To = "mikael@edebro.net"
newMail.Subject = Request.Form("subject")
newMail.Body = Request.Form("message")
newMail.Send
Set newMail = Nothing

End If
%\>

Nu hör det till saken att jag har fler fält. Bland annat:
\* Företag
\* telefonnummer
\* Fax
\* hemsida
\* Adress
\* ort

hur skriver jag för att få med mig detta???

Permalänk: https://www.webforum.nu/p/86760

## #2 — Palle, 2003-09-23T08:15Z

En variant.. 

```
[red]<%

' kolla om vi ska skicka iväg ett e-mail
If Len(Request.Form("email")) > 0 AND Len(Request.Form("subject")) > 0 AND Len(Request.Form("message")) > 0 Then

	[b]strBody[/b] = "Lite text här då.."[blue]&[/blue] vbcrlf &_
	"Företag: "& trim(Request.Form("foretag")) & vbcrlf &_
	"Telefon: "& trim(Request.Form("telefon")) & vbcrlf &_
	"o.s.v.."

	Set newMail = CreateObject("CDONTS.NewMail")
		newMail.From = Request.Form("email")
		newMail.To = "mikael@edebro.net"
		newMail.Subject = Request.Form("subject")
		newMail.Body = [b]strBody[/b]
		newMail.Send
	Set newMail = Nothing

End If

%> [/red]
```

**Redigerat:** Missade ett &-tecken..

&nbsp;

Permalänk: https://www.webforum.nu/p/1164716

## #3 — mackanz, 2003-09-23T08:40Z

Hejsan Palle!
Det fungerade ej.

Min kod ser ut så här:

\<%
' kolla om vi ska skicka iväg ett e-mail
If Len(Request.Form("email")) \> 0 AND Len(Request.Form("subject")) \> 0 AND Len(Request.Form("message")) \> 0 Then 
Set newMail = CreateObject("CDONTS.NewMail")
strBody = "Lite text här då.." vbcrlf &\_
	"Företag: "& trim(Request.Form("FORETAG")) & vbcrlf &\_
	"Adress: "& trim(Request.Form("ADRESS")) & vbcrlf &\_
	"Stad: "& trim(Request.Form("CITY")) & vbcrlf &\_
	"Telefon: "& trim(Request.Form("PHONE")) & vbcrlf &\_
	"Fax: "& trim(Request.Form("FAX")) & vbcrlf &\_
	"Hemsida: "& trim(Request.Form("HOMEPAGE")) & vbcrlf &\_

newMail.From = Request.Form("EMAIL")
newMail.To = "markus.redman@enterab.com"
newMail.Subject = Request.Form("SUBJECT")
newMail.Body = Request.Form("MESSAGE")
newMail.Send
Set newMail = Nothing

End If
%\>

\<%
'Response.Redirect("kontaktok.htm")
%\>

och då fick jag följande felmeddelande:

Microsoft VBScript compilation error '800a0401' 

Expected end of statement 

/kontaktsend.asp, line 15 

strBody = "Lite text här då.." vbcrlf &\_
\-------------------------------^

Permalänk: https://www.webforum.nu/p/1164730

## #4 — @nders, 2003-09-23T08:42Z

Du skall ha ett &-tecken före vbCrLf.

Permalänk: https://www.webforum.nu/p/1164731

## #5 — mrblonde, 2003-09-23T08:43Z

Du glömde ju ett &

> **mackanz skrev:**
>
> Hejsan Palle!
> Det fungerade ej.
> 
> Min kod ser ut så här:
> 
> \<%
> ' kolla om vi ska skicka iväg ett e-mail
> If Len(Request.Form("email")) \> 0 AND Len(Request.Form("subject")) \> 0 AND Len(Request.Form("message")) \> 0 Then 
> Set newMail = CreateObject("CDONTS.NewMail")
> strBody = "Lite text här då.." & vbcrlf &\_
> 	"Företag: "& trim(Request.Form("FORETAG")) & vbcrlf &\_
> 	"Adress: "& trim(Request.Form("ADRESS")) & vbcrlf &\_
> 	"Stad: "& trim(Request.Form("CITY")) & vbcrlf &\_
> 	"Telefon: "& trim(Request.Form("PHONE")) & vbcrlf &\_
> 	"Fax: "& trim(Request.Form("FAX")) & vbcrlf &\_
> 	"Hemsida: "& trim(Request.Form("HOMEPAGE")) & vbcrlf &\_
> 
> newMail.From = Request.Form("EMAIL")
> newMail.To = "markus.redman@enterab.com"
> newMail.Subject = Request.Form("SUBJECT")
> newMail.Body = Request.Form("MESSAGE")
> newMail.Send
> Set newMail = Nothing
> 
> End If
> %\>
> 
> 
> \<%
> 'Response.Redirect("kontaktok.htm")
> %\>
> 
> 
> 
> 
> 
> och då fick jag följande felmeddelande:
> 
> Microsoft VBScript compilation error '800a0401' 
> 
> Expected end of statement 
> 
> /kontaktsend.asp, line 15 
> 
> strBody = "Lite text här då.." vbcrlf &\_
> \-------------------------------^

Permalänk: https://www.webforum.nu/p/1164732

## #6 — mackanz, 2003-09-23T08:49Z

Okej!
När jag lade till det & tecknet och testade kom jag baar till en vit sidan. Innebär det att fungerar?? 
Jag får ju inget mail i min inbox.

Om jag lägger till en response.redirect som då leder till en bekräftelse sida får jag ett nytt felmeddelande:

```
Header Error 

/kontaktsend.asp, line 35 

The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.Response object error 'ASP 0156 : 80004005'
```

Permalänk: https://www.webforum.nu/p/1164733

## #7 — @nders, 2003-09-23T08:53Z

> **mackanz skrev:**
>
> Okej!
> När jag lade till det & tecknet och testade kom jag baar till en vit sidan. Innebär det att fungerar??

Nej, det beror ju på om/hur SMTP-tjänsten på maskinen är konfigurerad, samt om man angett en giltig avsändaradress.

> Om jag lägger till en response.redirect som då leder till en bekräftelse sida får jag ett nytt felmeddelande:
> 
> 
>
>
> ```
> Header Error 
> 
> /kontaktsend.asp, line 35 
> 
> The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.Response object error 'ASP 0156 : 80004005'
> ```

Sätt följande högst upp i ditt asp-dokument:

```
Response.buffer = true
```

Mvh

Permalänk: https://www.webforum.nu/p/1164739

## #8 — Palle, 2003-09-23T08:54Z

Denna då? 

```
[red]<%

Response.Buffer = True

' kolla om vi ska skicka iväg ett e-mail
If Len(Request.Form("email")) > 0 AND Len(Request.Form("subject")) > 0 AND Len(Request.Form("message")) > 0 Then

	strBody = "Lite text här då.."& vbcrlf &_
	"Företag: "& trim(Request.Form("FORETAG")) & vbcrlf &_
	"Adress: "& trim(Request.Form("ADRESS")) & vbcrlf &_
	"Stad: "& trim(Request.Form("CITY")) & vbcrlf &_
	"Telefon: "& trim(Request.Form("PHONE")) & vbcrlf &_
	"Fax: "& trim(Request.Form("FAX")) & vbcrlf &_
	"Hemsida: "& trim(Request.Form("HOMEPAGE")) & vbcrlf & vbcrlf &_
	"Meddelande: "& trim(Request.Form("MESSAGE"))

	Set newMail = CreateObject("CDONTS.NewMail")
		newMail.From = trim(Request.Form("EMAIL"))
		newMail.To = "markus.redman@enterab.com"
		newMail.Subject = Request.Form("SUBJECT")
		newMail.Body = strBody
		newMail.Send
	Set newMail = Nothing

	Response.Redirect "kontaktok.htm"

Else
	Response.Write "Nått är fel, mailet kunde inte skickas.."

End If

%>[/red]
```

Permalänk: https://www.webforum.nu/p/1164740

## #9 — mackanz, 2003-09-23T09:01Z

Samma felmeddelande fortfarande!

Tar jag bort  

```
 <%
Response.Redirect("kontaktok.htm")
%>
```

så kommer jag bara till en vit blank sida.
Jag får inga mail på det jag sänt in =(

Jag kör allt på en webbserver där jag laddar upp filerna.

Adress till sidan: <http://www.ifkolme.org/kontaktform.asp>

Permalänk: https://www.webforum.nu/p/1164747

## #10 — mackanz, 2003-09-23T09:03Z

Nu fick jag plötsligt detta felmeddelande: Jag är usel på att felmeddelanden. =)

```
Microsoft VBScript compilation error '800a03f9' 

Expected 'Then' 

/kontaktsend.asp, line 17 

If Len(Request.Form("email")) &gt; 0 AND Len(Request.Form("subject")) &gt; 0 AND Len(Request.Form("message")) &gt; 0 Then
---------------------------------^
```

Permalänk: https://www.webforum.nu/p/1164748

## #11 — Palle, 2003-09-23T09:05Z

..fungerade inte mitt senaste kod-förslag?
Det verkar som om du inte ändrat till den..

Permalänk: https://www.webforum.nu/p/1164749

## #12 — mackanz, 2003-09-23T09:09Z

Palle:
Koden du skrev 10.54 fungerade ej. Fick följande felmeddelande:

```
<% 
Response object error 'ASP 0156 : 80004005' 

Header Error 

/kontaktsend.asp, line 16 

The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.
```

Permalänk: https://www.webforum.nu/p/1164753

## #13 — mackanz, 2003-09-23T09:12Z

Palle:
När jag tog bort  Response.Buffer = True

kom följande text fram som finns med i koden:

\<% Nått är fel, mailet kunde inte skickas.

Permalänk: https://www.webforum.nu/p/1164755

## #14 — mackanz, 2003-09-23T09:46Z

med följande kod får jag meddelandet att Något är fel, mailet kunde inte skickas.

```
<%
' kolla om vi ska skicka iväg ett e-mail
If Len(Request.Form("EMAIL")) > 0 AND Len(Request.Form("SUBJECT")) > 0 AND Len(Request.Form("MESSAGE")) > 0 Then

	strBody = "Lite text här då.."& vbcrlf &_
	"Företag: "& trim(Request.Form("FORETAG")) & vbcrlf &_
	"Adress: "& trim(Request.Form("ADRESS")) & vbcrlf &_
	"Stad: "& trim(Request.Form("CITY")) & vbcrlf &_
	"Telefon: "& trim(Request.Form("PHONE")) & vbcrlf &_
	"Fax: "& trim(Request.Form("FAX")) & vbcrlf &_
	"Hemsida: "& trim(Request.Form("HOMEPAGE")) & vbcrlf & vbcrlf &_
	"Meddelande: "& trim(Request.Form("MESSAGE"))

	Set newMail = CreateObject("CDONTS.NewMail")
		newMail.From = trim(Request.Form("EMAIL"))
		newMail.To = "markus.redman@enterab.com"
		newMail.Subject = Request.Form("SUBJECT")
		newMail.Body = strBody
		newMail.Send
	Set newMail = Nothing
	
	

	Response.Redirect "kontaktok.htm"

Else
	Response.Write "Något är fel, mailet kunde inte skickas.."

End If

%>
```

Permalänk: https://www.webforum.nu/p/1164774

## #15 — @nders, 2003-09-23T09:49Z

Är alla tre fälten du kontrollerar ifyllda då?

Permalänk: https://www.webforum.nu/p/1164775

## #16 — @nders, 2003-09-23T09:52Z

Du har ju inte satt något namn på textarean, så om du använder fältnamnet MESSAGE för att hämta in datat, kommer det alltid vara en tom sträng och du hamnar i ELSE-delen av din if-sats.

Permalänk: https://www.webforum.nu/p/1164777

## #17 — mackanz, 2003-09-25T06:41Z

Stort tack till alla som hjälpte mig med detta problem.
Nu är allt löst.

Mvh. 
Markus

Permalänk: https://www.webforum.nu/p/1166016

## #18 — Zaiman, 2003-09-25T08:25Z

korta ned koden lite kanske?

```
sBody = ""
	For Each field In Request.Form
		sBody = sBody & field & ": " & Request.Form(field) & Chr(13) & Chr(10)
	Next
```

Så här skapar jag min body i en del av mina mailsidor.

Lite mindre kod...

Permalänk: https://www.webforum.nu/p/1166052

## #19 — grillkillen, 2003-09-25T10:11Z

Tänk på att du får med alla form-objekt om du använder en For Each Field. Även skicka-knappen, osv. Använd en if-sats för att få bort den.

Permalänk: https://www.webforum.nu/p/1166101

---

Tråden på webben: https://www.webforum.nu/amne/asp/86760-problem-med-cdonts
