ASP Sending e-mail with CDO

  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

email.asp
<html>
<head>

</head>
<body>
<form action="sendemail1.asp" method="post">
<p>To:</p>
<input type="text" name="to_field" />
<p>Message:</p>
<textarea name="message_field" rows="5"></textarea>
<input type="submit" value="Send Email" />
</form>
</body>
</html>

sendemail.asp
<%
dim to_field, message
to_field = Request.Form("to_field")
message = Request.Form("message")

'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

'Out going SMTP server
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smpt.ntlworld.com"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
objCDOSYSMail.From = "pri_amin5@hotmail.com" ' the address you want the email to be from
objCDOSYSMail.TO = to_field 'the address the mail is to be sent to
objCDOSYSMail.Subject = "Subject goes here"
objCDOSYSMail.HTMLBody = message
objCDOSYSMail.Send

'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
%>

ERROR MESSAGE

The page cannot be displayed
There is a problem with the page you are trying to reach and it cannot be displayed.

Please try the following:

* Click the Refresh button, or try again later.
* Open the x0.x.x9.xx3 home page, and then look for links to the information you want.

HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services

Technical Information (for support personnel)

* Error Type:
CDO.Message.1 (0x80040213)
The transport failed to connect to the server.
/email/sendemail1.asp, line 23

* Browser Type:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.7.5) Gecko/20041110 Firefox/1.0

* Page:
POST 51 bytes to /email/sendemail1.asp

* POST Data:
to_field=pri.amin%40gmail.com&message_field=yrtyrty

* Time:
23 February 2005, 10:25:45

* More information:
Microsoft Support

SO IN the webpage i can type any email address to send the email?!YES?

in the code i have also sated an email address (pri_amin5@hotmail.com) i think thats wrong!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

You spelled the same of your SMTP server wrong.
You've got "smpt.ntlworld.com" , it should be "smtp.ntlworld.com".
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

*plum*!!

thanks sooooo much mate!!!
it works!!! i recive a message from myself when i check my email!
is there away of changing the name that appears inn the email inbox?

also, how would i create a confirmation page to say message sent?

thanks again mate
sure u dont what 1gb of email storage??
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

No probs man, that's what I'm here for.
You could change the .From field to change which address it's from (theoretically, you could use any address).

As for the confirmation page - just use the page that does the sending. So, the code for your "sendemail.asp" file would be:

Code: [ Select ]
<%@ Language=VBScript %>
<html>
<head>

</head>
<body>
<%
dim to_field, message
to_field = Request.Form("to_field")
message = Request.Form("message")

'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

'Out going SMTP server
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.ntlworld.com"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
objCDOSYSMail.From = "pri_amin5@hotmail.com" ' the address you want the email to be from
objCDOSYSMail.TO = to_field 'the address the mail is to be sent to
objCDOSYSMail.Subject = "Subject goes here"
objCDOSYSMail.HTMLBody = message
objCDOSYSMail.Send

'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
%>
<p>Mail sent successfully to address <%=to_field%>!</p>
</body>
</html>
  1. <%@ Language=VBScript %>
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6. <%
  7. dim to_field, message
  8. to_field = Request.Form("to_field")
  9. message = Request.Form("message")
  10. 'Create the e-mail server object
  11. Set objCDOSYSMail = Server.CreateObject("CDO.Message")
  12. Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
  13. 'Out going SMTP server
  14. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.ntlworld.com"
  15. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  16. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  17. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
  18. objCDOSYSCon.Fields.Update
  19. 'Update the CDOSYS Configuration
  20. Set objCDOSYSMail.Configuration = objCDOSYSCon
  21. objCDOSYSMail.From = "pri_amin5@hotmail.com" ' the address you want the email to be from
  22. objCDOSYSMail.TO = to_field 'the address the mail is to be sent to
  23. objCDOSYSMail.Subject = "Subject goes here"
  24. objCDOSYSMail.HTMLBody = message
  25. objCDOSYSMail.Send
  26. 'Close the server mail object
  27. Set objCDOSYSMail = Nothing
  28. Set objCDOSYSCon = Nothing
  29. %>
  30. <p>Mail sent successfully to address <%=to_field%>!</p>
  31. </body>
  32. </html>


If the mail can't be sent, IIS will generate an error (similar to what you were seeing when it wasn't working). Hence, this page will only be displayed if the mail is actually send. Thus, the user only sees the confirmation if there wasn't any errors.
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

thanks again mate,
but when i check my email, the new messgae arrives but NO text is shown!

i think the to files are using two different text areas!!

any comments??

thanks
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

Sorry, replace the line:
Code: [ Select ]
message = Request.Form("message")

With:
Code: [ Select ]
message = Request.Form("message_field")


If you try to retrieve a variable from the form/session/querystring that has not yet been set, you get an empty string, i.e. "". You'd think it would cause an error, but no. That's why you weren't getting the message in the email - the message was set to "".
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

mate your a *peach* genies!!!!!!!

it works! just need to sort out the subject field, for that do i just create a subject field, and name it correctly to what it is called in the code,
i.e. objCDOSYSMail.Subject = "Subject goes here"

oh and the confirmation page does not appear, just a blank page.

Is it unsecure to give out my IP address to access my site to othere peeple??
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

ooowwwee

This is my 100th post!! Thanks for all your help and sorry if i asked so many dumb Q's, your help is well appreciated
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

pritesh_a wrote:
it works! just need to sort out the subject field, for that do i just create a subject field, and name it correctly to what it is called in the code,
i.e. objCDOSYSMail.Subject = "Subject goes here"

oh and the confirmation page does not appear, just a blank page.

Is it unsecure to give out my IP address to access my site to othere peeple??


To add the subject, create another text field on your "post" page, and on the "send" page, create a variable to get the subject field's value. Then, as you say, replace the "Mail.Subject = "Subject goes here"" with the variable and you're laughing!

The confirmation page should appear - did you include the <p>..</p> tags with the confirmation message?

I'm not sure about the IP thing. It will probably be ok, but I don't know.

Glad to be of assistance :D
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

Mail sent successfully to address pri.amin@gmail.com!

ooowwweee working at last!!! thanks mate

Ok just gona try the subject filed, and il get back to u!
thanks again
  • nellaikumar
  • Born
  • Born
  • nellaikumar
  • Posts: 1
  • Loc: Bangalore

Post 3+ Months Ago

Hi,
I am very new this forum. I got the following error while executing Mail code.


My code :


<%
dim to_field, message
to_field = Request.Form("to_field")
message = Request.Form("message")

'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

'Out going SMTP server
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smpt.ntlworld.com"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
objCDOSYSMail.From = "nellaikumar2002@rediffmail.com" ' the address you want the email to be from
objCDOSYSMail.TO = to_field 'the address the mail is to be sent to
objCDOSYSMail.Subject = "Subject goes here"
objCDOSYSMail.HTMLBody = message
objCDOSYSMail.Send

'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
%>

Error Message :

Technical Information (for support personnel)

Error Type:
CDO.Message.1 (0x80040213)
The transport failed to connect to the server.
/16/cdosys/sendemail.asp, line 24


Seeks help regarding this CDOSYS Mail.

Thanks,
P.Nellaikumar.
nellaikumar2002@rediffmail.com

pritesh_a wrote:
*plum*!

thanks sooooo much mate!
it works! i recive a message from myself when i check my email!
is there away of changing the name that appears inn the email inbox?

also, how would i create a confirmation page to say message sent?

thanks again mate
sure u dont what 1gb of email storage??
  • Jereme.Guenther
  • Born
  • Born
  • Jereme.Guenther
  • Posts: 1

Post 3+ Months Ago

I have been fighting a similar issue myself. I have my own server on which I installed windows 2003, iis6, SMTP virtual server. I have pointed my SMTP server to my companies personal smart host. I have finally succeeded in getting the following code to run correctly:

Code: [ Select ]
  Set cdoConfig = CreateObject("CDO.Configuration")

  With cdoConfig.Fields
    .Item(cdoSendUsingMethod) = cdoSendUsingPort
    .Item(cdoSMTPServer) = "localhost"
    .Item(cdoSMTPAuthenticate) = cdoNTLM
'    .Item(cdoSendUsername) = "username"
'    .Item(cdoSendPassword) = "password"
    .Update
  End With

    Set theMail= CreateObject("CDO.Message")
    theMail.Configuration = cdoConfig
    Select Case EmailBodyStyle
        Case "text"
            theMail.TextBody=EmailBody
        Case "html"
            theMail.HTMLBody=EmailBody
    End Select
    theMail.From=EmailFrom
    theMail.To=EmailTo
    theMail.subject=EmailSubject
    theMail.Send
    set theMail = Nothing
        Set cdoConfig = Nothing
  1.   Set cdoConfig = CreateObject("CDO.Configuration")
  2.   With cdoConfig.Fields
  3.     .Item(cdoSendUsingMethod) = cdoSendUsingPort
  4.     .Item(cdoSMTPServer) = "localhost"
  5.     .Item(cdoSMTPAuthenticate) = cdoNTLM
  6. '    .Item(cdoSendUsername) = "username"
  7. '    .Item(cdoSendPassword) = "password"
  8.     .Update
  9.   End With
  10.     Set theMail= CreateObject("CDO.Message")
  11.     theMail.Configuration = cdoConfig
  12.     Select Case EmailBodyStyle
  13.         Case "text"
  14.             theMail.TextBody=EmailBody
  15.         Case "html"
  16.             theMail.HTMLBody=EmailBody
  17.     End Select
  18.     theMail.From=EmailFrom
  19.     theMail.To=EmailTo
  20.     theMail.subject=EmailSubject
  21.     theMail.Send
  22.     set theMail = Nothing
  23.         Set cdoConfig = Nothing


Just thought I would pass this along. I have another windows 2003 server running iis6, SMTP Virtual... just like my first one and I can get it to run just fine without the CDO.Configuration code, however I must admit that even though it runs without errors it has recently quit sending off the email.

However, the biggest stumbling block for me when upgrading this code from the original CDONTS code was that I forgot to install SMTP on the new server. I am still confused as to why I need the CDO.Configuration code as all that information should default for me, but at least it is working.

Oh, I forgot to mention that it also took me a bit to figure out that the old adovbs file was replaced with:
Code: [ Select ]
<!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows 2000 Library" -->
<!--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" -->
  1. <!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows 2000 Library" -->
  2. <!--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" -->
  • mkhawarbashir
  • Born
  • Born
  • mkhawarbashir
  • Posts: 3

Post 3+ Months Ago

I have made a page to run the same code but getting this message while it is called from otherpage.

Open IIS Help, which is accessible in IIS Manager (inetmgr), and search for topics titled Web Site Setup, Common Administrative Tasks, and About Custom Error Messages

can u tell what and where the problem is? i will be thankful.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

You didn't specify the actual error, mkhawarbashir

What is the actual error message and can you post the mail code you are using as well?
  • mkhawarbashir
  • Born
  • Born
  • mkhawarbashir
  • Posts: 3

Post 3+ Months Ago

This is the code written in asp file

<%

Dim varfrom, varto, varsubject, varcomments,t1name
varfrom=Request.Form("txtfrom")
varto=Request.Form("listto")
varsubject=Request.Form("txtsubject")
varcomments=Request.Form("txtcomments")

dim objCDOSYSMail, objCDOSYSCon
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

'Out going SMTP server
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.uvas.edu.pk"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
objCDOSYSMail.From = varfrom
objCDOSYSMail.TO = varto
objCDOSYSMail.Subject = varsubject
objCDOSYSMail.HTMLBody = varcomments
objCDOSYSMail.Send
Set objCDOSYSMail=Nothing
Response.write "Thank You"
%>

and receiving following error message

Please try the following:

Make sure that the Web site address displayed in the address bar of your browser is spelled and formatted correctly.
If you reached this page by clicking a link, contact the Web site administrator to alert them that the link is incorrectly formatted.
Click the Back button to try another link.
HTTP Error 404 - File or directory not found.
Internet Information Services (IIS)

--------------------------------------------------------------------------------

Technical Information (for support personnel)

Go to Microsoft Product Support Services and perform a title search for the words HTTP and 404.
Open IIS Help, which is accessible in IIS Manager (inetmgr), and search for topics titled Web Site Setup, Common Administrative Tasks, and About Custom Error Messages.


I will wait for ur reply
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

mkhawarbashir wrote:
I have made a page to run the same code but getting this message while it is called from otherpage.


Well, the error you posted basically seems to be indicating that your form must be on another page. I would double check your "action" in your form and make sure it is set to go to the mail script page. The problem almost has to be in your form action. Check spelling, typos, case, bad relative link, etc. If a relative link to the mail script isn't working try an absolute link.
  • mkhawarbashir
  • Born
  • Born
  • mkhawarbashir
  • Posts: 3

Post 3+ Months Ago

Thnaks for ur cooperation, following line is written in the page which is calling that asp file.

<form name="uvasfeedback" action="feedback.asp" method="post">

Now please tell me what and where the problem is? I will be very thankful.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

Well the action looks OK, but is feedback.asp located in the same directory as the form? Or is the form part of feedback.asp? If it's not located in the same directory as the file that contains the form then the path is wrong and you would simply have to correct the path. You have it written correctly but it depends on where feedback.asp is located as to whether the path is correct.
  • ra_22@rediffmail.com
  • Born
  • Born
  • ra_22@rediffmail.com
  • Posts: 1

Post 3+ Months Ago

Hi I am new to the form and this is my first post.

i just copied and pasted the code shown below, into an ASP page but the following error comes up.

HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services

Error Type:
CDO.Message.1 (0x80040213)
The transport failed to connect to the server.
/test/mail/sendmail.asp, line 23


<%
dim to_field, message
to_field = Request.Form("to_field")
message = Request.Form("message")

'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

'Out going SMTP server
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.ntlworld.com"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
objCDOSYSMail.From = "get_jobs@yahoo.com" ' the address you want the email to be from
objCDOSYSMail.TO = to_field 'the address the mail is to be sent to
objCDOSYSMail.Subject = "Subject goes here"
objCDOSYSMail.HTMLBody = message
objCDOSYSMail.Send

'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
%>


I am using windows 2000 box

I have installed IIS on my system

i am connected to internet when i am running the script.

I am trying to test it locally on my system using the http://localhost/...

do i need to configure my default smtp server on the IIS server.

i have tried many cdo objects on the internet, pasted and tried, looks like it sent emails but when you check your account nothing happens.

can you help please.


happens
  • KarlZ
  • Born
  • Born
  • KarlZ
  • Posts: 4

Post 3+ Months Ago

Hi,

I've read many threads on this problem since I'm stuck with a similar one.

I have a form wich uses an asp to send emails.
In explorer 5.2.3 for Mac it works just fine, but nowhere else.

I get the error:
CDO.Message.1 error '8004020d'
At least one of the From or Sender fields is required, and neither was found.

and then a reference to a line in the asp-code wich is line 40 (in the code it's - myMail.Send )

How ist it possible to work in one world and not the other?

I have checked and doublechecked the spelling of yhe formlabels and since the form works fine i Explorer Mac - but not in PC ---- aaargh :x I'm going nuts with this!

Has anyone heard of this before or have any tips of a soulution?

Thanks,
K
  • zaneta
  • Born
  • Born
  • zaneta
  • Posts: 1

Post 3+ Months Ago

Hi everyone!
I am as green to scripting as I don't know what!
My code is not good and all I get is a blank page!
I use cdosys.
First the page had different errors ...0404 etc, now it is blank.
Don't receive emails at all.
Please, can you help and have a look at this piece for me and tell me what I have done "funny" to this.

It has driven me up the wall and my contact page cannot work properly.
Many many huge thanks in advance.

We all started from null, so have hope for me please.

Zaneta :cry:

That is the script:

<%@ Language=VBScript %>
<html>
<head>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
body {
background-color: #000000;
}
-->
</style>
</head>
<body>
<div align="center" class="style1">
<%

referers = Array("www.Domain.Dom")
mailComp = "CDOSYS"
smtpServer = "intmail.atlas.pipex.net"
fromAddr = "Your email address"






Response.Buffer = true
errorMsgs = Array()

'Check for form data.

if Request.ServerVariables("Content_Length") = 0 then
call AddErrorMsg("No form data submitted.")
end if

'Check if referer is allowed.

if UBound(referers) >= 0 then
validReferer = false
referer = GetHost(Request.ServerVariables("HTTP_REFERER"))
for each host in referers
if host = referer then
validReferer = true
end if
next
if not validReferer then
if referer = "" then
call AddErrorMsg("No referer.")
else
call AddErrorMsg("Invalid referer: '" & referer & "'.")
end if
end if
end if

'Check for the recipients field.

if Request.Form("_recipients") = "" then
call AddErrorMsg("Missing email recipient.")
end if

'Check all recipient email addresses.

recipients = Split(Request.Form("_recipients"), ",")
for each name in recipients
name = Trim(name)
if not IsValidEmailAddress(name) then
call AddErrorMsg("Invalid email address in recipient list: " & name & ".")
end if
next
recipients = Join(recipients, ",")

'Get replyTo email address from specified field, if given, and check it.

name = Trim(Request.Form("_replyToField"))
if name <> "" then
replyTo = Request.Form(name)
else
replyTo = Request.Form("_replyTo")
end if
if replyTo <> "" then
if not IsValidEmailAddress(replyTo) then
call AddErrorMsg("Invalid email address in reply-to field: " & replyTo & ".")
end if
end if

'Get subject text.

subject = Request.Form("_subject")

'If required fields are specified, check for them.

if Request.Form("_requiredFields") <> "" then
required = Split(Request.Form("_requiredFields"), ",")
for each name in required
name = Trim(name)
if Left(name, 1) <> "_" and Request.Form(name) = "" then
call AddErrorMsg("Missing value for " & name)
end if
next
end if

'If a field order was given, use it. Otherwise use the order the fields were
'received in.

str = ""
if Request.Form("_fieldOrder") <> "" then
fieldOrder = Split(Request.Form("_fieldOrder"), ",")
for each name in fieldOrder
if str <> "" then
str = str & ","
end if
str = str & Trim(name)
next
fieldOrder = Split(str, ",")
else
fieldOrder = FormFieldList()
end if

'If there were no errors, build the email note and send it.

if UBound(errorMsgs) < 0 then

'Build table of form fields and values.

body = "<table border=""0"" cellpadding=""2"" cellspacing=""0"">" & vbCrLf
for each name in fieldOrder
body = body _
& "<tr valign=""top"">" _
& "<td><b>" & name & ":</b></td>" _
& "<td>" & Request.Form(name) & "</td>" _
& "</tr>" & vbCrLf
next
body = body & "</table>" & vbCrLf

'Add a table for any requested environmental variables.

if Request.Form("_envars") <> "" then
body = body _
& "<p>&nbsp;</p>" & vbCrLf _
& "<table border=""0"" cellpadding=""2"" cellspacing=""0"">" & vbCrLf
envars = Split(Request.Form("_envars"), ",")
for each name in envars
name = Trim(name)
body = body _
& "<tr valign=""top"">" _
& "<td><b>" & name & ":</b></td>" _
& "<td>" & Request.ServerVariables(name) & "</td>" _
& "</tr>" & vbCrLf
next
body = body & "</table>" & vbCrLf
end if

'Send it.

str = SendMail()
if str <> "" then
AddErrorMsg(str)
end if

'Redirect if a URL was given.

if Request.Form("_redirect") <> "" then
Response.Redirect(Request.Form("_redirect"))
end if

end if %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
</div>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FormMail</title>
<div align="center" class="style1">
<style type="text/css">

body {
background-color: #ffffff;
color: #000000;
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
}

table {
border: solid 1px #000000;
border-collapse: collapse;
}

td, th {
border: solid 1px #000000;
border-collapse: collapse;
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
padding: 2px;
padding-left: 8px;
padding-right: 8px;
}

th {
background-color: #c0c0c0;
}

.error {
color: #c00000;
}

</style>
</head>
<body>

<% if UBound(errorMsgs) >= 0 then %>
<% else %>
</div>
<table align="center" cellpadding="0" cellspacing="0">
<tr>
<th colspan="2" align="center" valign="bottom" bgcolor="#000000" class="style1">
<div align="center">Thank you, the following information has been sent: </div></th>
</tr>
<% for each name in fieldOrder %>
<tr valign="top">
<td align="center" valign="middle" class="style1"><b>
<% = name %></b></td>
<td class="style1"><% = Request.Form(name) %></td>
</tr>
<% next %>
</table>
<div align="center"><span class="style1">
<% end if %>
</span>
</div>
</body>
</html>

<% '---------------------------------------------------------------------------
' Subroutines and functions.
'---------------------------------------------------------------------------

sub AddErrorMsg(msg)

dim n

'Add an error message to the list.

n = UBound(errorMsgs)
Redim Preserve errorMsgs(n + 1)
errorMsgs(n + 1) = msg

end sub

function GetHost(url)

dim i, s

GetHost = ""

'Strip down to host or IP address and port number, if any.

if Left(url, 7) = "http://" then
s = Mid(url, 8)
elseif Left(url, 8) = "https://" then
s = Mid(url, 9)
end if
i = InStr(s, "/")
if i > 1 then
s = Mid(s, 1, i - 1)
end if

getHost = s

end function

'Define the global list of valid TLDs.

dim validTlds

function IsValidEmailAddress(emailAddr)

dim i, localPart, domain, charCode, subdomain, subdomains, tld

'Check for valid syntax in an email address.

IsValidEmailAddress = true

'Parse out the local part and the domain.

i = InStrRev(emailAddr, "@")
if i <= 1 then
IsValidEmailAddress = false
exit function
end if
localPart = Left(emailAddr, i - 1)
domain = Mid(emailAddr, i + 1)
if Len(localPart) < 1 or Len(domain) < 3 then
IsValidEmailAddress = false
exit function
end if

'Check for invalid characters in the local part.

for i = 1 to Len(localPart)
charCode = Asc(Mid(localPart, i, 1))
if charCode < 32 or charCode >= 127 then
IsValidEmailAddress = false
exit function
end if
next

'Check for invalid characters in the domain.

domain = LCase(domain)
for i = 1 to Len(domain)
charCode = Asc(Mid(domain, i, 1))
if not ((charCode >= 97 and charCode <= 122) or (charCode >= 48 and charCode <= 57) or charCode = 45 or charCode = 46) then
IsValidEmailAddress = false
exit function
end if
next

'Check each subdomain.

subdomains = Split(domain, ".")
for each subdomain in subdomains
if Len(subdomain) < 1 then
IsValidEmailAddress = false
exit function
end if
next

'Last subdomain should be a TDL.

tld = subdomains(UBound(subdomains))
if not IsArray(validTlds) then
call SetValidTlds()
end if
for i = LBound(validTlds) to UBound(validTlds)
if tld = validTlds(i) then
exit function
end if
next
IsValidEmailAddress = false

end function

sub setValidTlds()

'Load the global list of valid TLDs.

validTlds = Array("aero", "biz", "com", "coop", "edu", "gov", "info", "int", "mil", "museum", "name", "net", "org", "pro", _
"ac", "ad", "ae", "af", "ag", "ai", "al", "am", "an", "ao", "aq", "ar", "as", "at", "au", "aw", "az", _
"ba", "bb", "bd", "be", "boyfriend", "bg", "bh", "bi", "bj", "bm", "bn", "bo", "br", "bs", "bt", "bv", "bw", "by", "bz", _
"ca", "cc", "cd", "cf", "cg", "ch", "ci", "ck", "cl", "cm", "cn", "co", "cr", "cu", "cv", "cx", "cy", "cz", _
"de", "dj", "dk", "dm", "do", "dz", "ec", "ee", "eg", "eh", "er", "es", "et", _
"fi", "fj", "fk", "fm", "fo", "fr", _
"ga", "gd", "ge", "girlfriend", "gg", "gh", "gi", "gl", "gm", "gn", "gp", "gq", "gr", "gs", "gt", "gu", "gw", "gy", _
"hk", "hm", "hn", "hr", "ht", "hu", _
"id", "ie", "il", "im", "in", "io", "iq", "ir", "is", "it", _
"je", "jm", "jo", "jp", _
"ke", "kg", "kh", "ki", "km", "kn", "kp", "kr", "kw", "ky", "kz", _
"la", "lb", "lc", "li", "lk", "lr", "ls", "lt", "lu", "lv", "ly", _
"ma", "mc", "md", "mg", "mh", "mk", "ml", "mm", "mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", "mv", "mw ", "mx", "my", "mz", _
"na", "nc", "ne", "nf", "ng", "ni", "nl", "no", "np", "nr", "nu", "nz", _
"om", _
"pa", "pe", "pf", "pg", "ph", "pk", "pl", "pm", "pn", "pr", "ps", "pt", "pw", "py", _
"qa", _
"re", "ro", "ru", "rw", _
"sa", "sb", "sc", "sd", "se", "sg", "sh", "si", "sj", "sk", "sl", "sm", "sn", "so", "sr", "st", "sv", "sy", "sz", _
"tc", "td", "tf", "tg", "th", "tj", "tk", "tm", "tn", "to", "tp", "tr", "tt", "tv", "tw", "tz", _
"ua", "ug", "uk", "um", "us", "uy", "uz", _
"va", "vc", "ve", "vg", "vi", "vn", "vu", _
"wf", "ws", _
"ye", "yt", "yu", _
"za", "zm", "zw")

end sub

function FormFieldList()

dim str, i, name

'Build an array of form field names ordered as they were received.

str = ""
for i = 1 to Request.Form.Count
for each name in Request.Form
if Left(name, 1) <> "_" and Request.Form(name) is Request.Form(i) then
if str <> "" then
str = str & ","
end if
str = str & name
exit for
end if
next
next
FormFieldList = Split(str, ",")

end function

function SendMail()

dim mailObj, cdoMessage, cdoConfig
dim addrList

'Send email based on mail component. Uses global variables for parameters
'because there are so many.

SendMail = ""

if mailComp = "CDOSYS" then
set cdoMessage = Server.CreateObject("CDO.Message")
set cdoConfig = Server.CreateObject("CDO.Configuration")
cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "intmail.atlas.pipex.net"
cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

'You need to edit the next two lines
cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "jellybean18@thewitchez.com"
cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Delfin18"


cdoConfig.Fields.Update
set cdoMessage.Configuration = cdoConfig
cdoMessage.From = fromAddr
cdoMessage.ReplyTo = replyTo
cdoMessage.To = recipients
cdoMessage.Subject = subject
cdoMessage.HtmlBody = body
on error resume next
cdoMessage.Send
if Err.Number <> 0 then
SendMail = "Email send failed: " & Err.Description & "."
end if
set cdoMessage = Nothing
set cdoConfig = Nothing
exit function
end if
end function %>
</body>
</html>
  • Ltat42a
  • Born
  • Born
  • Ltat42a
  • Posts: 1

Post 3+ Months Ago

I have a question regarding this CDO script. I have a HTML webpage with a user input form. When the users clicks Submit, the script works fine. What I'm looking for, is for the script to send me the results of the form to me in the email.

cdoMessage.Subject = "Comments from the website"
cdoMessage.TextBody = "WHAT DO I PUT HERE FOR THE SCRIPT TO SEND ME THE FORM PAGE RESULTS?"

Thanx in advance.

Post Information

  • Total Posts in this topic: 52 posts
  • Users browsing this forum: No registered users and 91 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.