ASP Sending e-mail with CDO

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

Post 3+ Months Ago

i want to send e-mails from my website! i.e allow users to create and send emails to who ever!

I have the asp code to send the e-mail, but do i need to create the form for this page i.e. in DWMX?

and just put the code in between the HTML code?

code from http://www.w3schools.com/asp/asp_send_email.asp
<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="mymail@mydomain.com"
myMail.To="someone@somedomain.com"
myMail.HTMLBody = "<h1>This is a message.</h1>"
myMail.Send
%>

or

<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="mymail@mydomain.com"
myMail.To="someone@somedomain.com"
myMail.TextBody="This is a message."
myMail.Send
%>

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

Post 3+ Months Ago

Well, you'll need to post the values to the ASP page that is to send the email:
Code: [ Select ]
<html>
<head>

</head>
<body>
<form action="send_email_page.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>
  1. <html>
  2. <head>
  3. </head>
  4. <body>
  5. <form action="send_email_page.asp" method="post">
  6. <p>To:</p>
  7. <input type="text" name="to_field" />
  8. <p>Message:</p>
  9. <textarea name="message_field" rows="5"></textarea>
  10. <input type="submit" value="Send Email" />
  11. </form>
  12. </body>
  13. </html>


Then, on your processing page:
Code: [ Select ]
<%
  dim to, message
  to = Request.Form("to_field")
  message = Request.Form("message_field")
  Set myMail=CreateObject("CDO.Message")
  myMail.Subject="Sending email with CDO"
  myMail.From="mymail@mydomain.com"
  myMail.To= to
  myMail.HTMLBody = message
  myMail.Send
%>
  1. <%
  2.   dim to, message
  3.   to = Request.Form("to_field")
  4.   message = Request.Form("message_field")
  5.   Set myMail=CreateObject("CDO.Message")
  6.   myMail.Subject="Sending email with CDO"
  7.   myMail.From="mymail@mydomain.com"
  8.   myMail.To= to
  9.   myMail.HTMLBody = message
  10.   myMail.Send
  11. %>


Obviously you'll need additional processing to check if it's a valid email address, whether the text entered contains illegal characters etc.
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

um very helpful thank you katana!!!
im still having problems..i might have to post all the code up!

;-((
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

"Obviously you'll need additional processing to check if it's a valid email address, whether the text entered contains illegal characters etc."

what sort of code are we talking?ad refferances?
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

No probs, that's what this place is for ;) :D
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

Well, you'll want to check that the email address at least contains the 'at' symbol (@), otherwise strange and unearthly things may happen.
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

right im gona sound so dumb...

iv got two pages in a testing folder on my ISS!(wwwroot)

the folder is called email inside the folder my two files
- email.asp
<html>
<head>

</head>
<body>
<form action="sendemail.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>

and page to
- sendemail.asp
<%
dim to, message
to = Request.Form("to_field")
message = Request.Form("message_field")
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="pri.amin5@hotmail.com"
myMail.To= to
myMail.HTMLBody = message
myMail.Send
%>

this is not working, im not suprised cos i think it looks very wrong
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

What is causing it not to work? What (if any) error message are you getting?
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

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 xx.x.xx.xxx 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:
Microsoft VBScript compilation (0x800A03F2)
Expected identifier
/email/sendemail.asp, line 2, column 4
dim to, message
---^

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

* Page:
POST 60 bytes to /email/sendemail.asp

* POST Data:
to_field=pri.amin%40gmail.com&message_field=hello+email+test

* Time:
22 February 2005, 22:17:41

* More information:
Microsoft Support

error message!

right another Q, is it safe to give people my IP address to access my website>
i.e
80.108.63.2/email/email.asp

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

Post 3+ Months Ago

Just a thought (I don't have Visual Studio at home so no syntax highlighting for me), I think 'to' is a reserved keyword. change it to something else and give it a try (i.e. to_field)
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

ok...
in the 2nd page
-sendemail.asp

<%
dim to, message
to = Request.Form("to_field")
message = Request.Form("message_field")
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="pri.amin5@hotmail.com"
myMail.To= to
myMail.HTMLBody = message
myMail.Send
%>

change the above
myMail.To=to
to
myMail.To_Field=to

is that right?
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

No, no. Change the variable 'to':

Code: [ Select ]
<%
dim to_field, message
to_field = Request.Form("to_field")
message = Request.Form("message_field")
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="pri.amin5@hotmail.com"
myMail.To= to_field
myMail.HTMLBody = message
myMail.Send
%>
  1. <%
  2. dim to_field, message
  3. to_field = Request.Form("to_field")
  4. message = Request.Form("message_field")
  5. Set myMail=CreateObject("CDO.Message")
  6. myMail.Subject="Sending email with CDO"
  7. myMail.From="pri.amin5@hotmail.com"
  8. myMail.To= to_field
  9. myMail.HTMLBody = message
  10. myMail.Send
  11. %>
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

no
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 xxx.x.xxx.xxx 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 (0x80040220)
The "SendUsing" configuration value is invalid.
/email/sendemail.asp, line 10

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

* Page:
POST 50 bytes to /email/sendemail.asp

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

* Time:
22 February 2005, 22:34:23

* More information:
Microsoft Support

do i need a third page for the confirmation page?
and do i need to specify the email address in the code?
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

It's a CDO error this time, which means that the last one has been sorted. Have you set it up so that CDO knows the address of your SMTP server etc?

Google for the text " CDO.Message.1 (0x80040220) ", one of the results is this: http://www.webmasterworld.com/forum47/1941.htm
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

are u trying to be funny?
i have to sign up to that fourm!!
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

You don't have to join it! It's someone who has posted the same problem as you. I'm merely suggesting that you follow the advice given to this guy. I program in ASP at work, and as such, all my ASP files/books are there. Hence, I can't look up the error code to find out what the cause may be.

As I say, check google. From what I've seen, you may have to configure your server's CDO to take into account your SMTP server. I have personally never had to do that, as my work's version was previously set-up.
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

ok thanks mate.
i cant actually view that topic on that website, it wont help me.

iv tried typring in the error message text:
Error Type CDO.Message.1 (0x80040220)
into google, no joy

do u wana see all my code so far?

thanks for all the help
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

Yeah, post the full code. I'm turning in for the nite soon, but I'll have a look at it in the morning when I get to work.
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

two files called
email.asp
<html>
<head>

</head>
<body>
<form action="sendemail.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>

file 2
sendemail.asp
<%
dim to_field, message
to_field = Request.Form("to_field")
message = Request.Form("message_field")
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="pri.amin5@hotmail.com"
myMail.To= to_field
myMail.HTMLBody = message
myMail.Send
%>

the above is ALL the code from the 2files.

any help is grateful
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

Using the above code, I was able to send an email to myself, apparantly from "pri.amin5@hotmail.com" with "Sending email with CDO" as the subject.
Hence, my CDO configuration is working. You'll need to figure out how to configure CDO to point to your SMTP server (so it knows where to send the email).

Here is the example that was contained in the link I had previously posted. I don't know if this works, as my CDO is properly configured and I don't want to mess about with it.
Code: [ Select ]
'Dimension variables
Dim objCDOSYSCon

'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") = "mail.example.co.uk"
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 = "orders@example.co.uk"
objCDOSYSMail.TO = "Email Address"
objCDOSYSMail.BCC = "any@example.co.uk"
objCDOSYSMail.Subject = "Subject goes here"
objCDOSYSMail.HTMLBody = "<html><p>Html formatted message goes here</p></html>"
objCDOSYSMail.Send

'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
  1. 'Dimension variables
  2. Dim objCDOSYSCon
  3. 'Create the e-mail server object
  4. Set objCDOSYSMail = Server.CreateObject("CDO.Message")
  5. Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
  6. 'Out going SMTP server
  7. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.example.co.uk"
  8. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  9. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  10. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
  11. objCDOSYSCon.Fields.Update
  12. 'Update the CDOSYS Configuration
  13. Set objCDOSYSMail.Configuration = objCDOSYSCon
  14. objCDOSYSMail.From = "orders@example.co.uk"
  15. objCDOSYSMail.TO = "Email Address"
  16. objCDOSYSMail.BCC = "any@example.co.uk"
  17. objCDOSYSMail.Subject = "Subject goes here"
  18. objCDOSYSMail.HTMLBody = "<html><p>Html formatted message goes here</p></html>"
  19. objCDOSYSMail.Send
  20. 'Close the server mail object
  21. Set objCDOSYSMail = Nothing
  22. Set objCDOSYSCon = Nothing


Obviously this can be adapted to suit your variable names etc.
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

so i need to configure my CDO?
how do i go about doing that?
where can i see my SMPT settings?

so the email i send from my site, is using the email address pri_amin5@hotmail.com to send the message??
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

Using the example above!
see the line "Set objCDOSYSCon = Server.CreateObject("CDO.Configuration")"? That creates a new CDO configuration object. The next block of code in the example sets up the settings for your SMTP server. The configuration object then gets assigned to the CDO Mail message.
Are you running your own mail server? If so, enter the domain name/IP of this in the configuration (in place of "mail.example.co.uk"). If not, your ISP most probably provides you with some SMTP server settings in order for you to send email. If you have Outlook Express (or a similar program) and use this to check your email, your settings will be stored in there. Failing that, ask your ISP what the SMTP server is (usually it's something like "smtp.blueyonder.co.uk").
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

no i dont think im running my own mail server, i use my hotmail or gmail account!

the code u posted above will be placed in my sencond, sendemail.asp file RIGHT?

do i just need to change
objCDOSYSMail.From = "orders@example.co.uk"

putting in my email address
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

You would know if you were running your own mail server. You can't use Hotmail or Gmail is your SMTP server as these are internet based mail services. As I said, find out the address of your ISP's mail server. Who provides your internet connection? BT? Tiscali? Wanadoo? They will have an SMTP server set up sepecifically to handle mail. You will need this address, as you will need this server to actually send your message.

Correct, the code I posted goes in the second file. Once you have found out your SMTP server address, the code will look something like this:
Code: [ Select ]
dim to_field, 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") = "MY_ISP_SMTP_SERVER_ADDRESS"
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 = "me@myhost.co.uk" ' 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
  1. dim to_field, message
  2. 'Create the e-mail server object
  3. Set objCDOSYSMail = Server.CreateObject("CDO.Message")
  4. Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
  5. 'Out going SMTP server
  6. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "MY_ISP_SMTP_SERVER_ADDRESS"
  7. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  8. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  9. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
  10. objCDOSYSCon.Fields.Update
  11. 'Update the CDOSYS Configuration
  12. Set objCDOSYSMail.Configuration = objCDOSYSCon
  13. objCDOSYSMail.From = "me@myhost.co.uk" ' the address you want the email to be from
  14. objCDOSYSMail.TO = to_field 'the address the mail is to be sent to
  15. objCDOSYSMail.Subject = "Subject goes here"
  16. objCDOSYSMail.HTMLBody = message
  17. objCDOSYSMail.Send
  18. 'Close the server mail object
  19. Set objCDOSYSMail = Nothing
  20. Set objCDOSYSCon = Nothing
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

thanls so much mate,
im going to try find out my SMPT address, im using NTL, i should have it writen down somewhere!

i thinh the SMPT is:
smpt.ntlworld.com
sound write?


Would u like a very large email storage space for you all your help? FREE
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

That sounds about right.

Give it a try and let me know how it goes.
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

Right, the two files as follow:
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>

file2
sendemail1.asp
<%
dim to_field, 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 = "navin.amin@ntlworld.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
%>

NOT WORKING
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 xx.x.xxx.xx 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 (0x8004020C)
At least one recipient is required, but none were found.
/email/sendemail1.asp, line 20

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

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

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

* Time:
23 February 2005, 09:56:20

* More information:
Microsoft Support

if i go to Control pannel, then, Admin Tools, open IIS, right click on my Default SMTP Virtual Server
the properties fir IP address are UNASSIGNED,
sould my IP addess be in this section??
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

Forgot to get the variables from the FORM:

Code: [ Select ]
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") = "MY_ISP_SMTP_SERVER_ADDRESS"
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 = "me@myhost.co.uk" ' 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
  1. dim to_field, message
  2. to_field = Request.Form("to_field")
  3. message = Request.Form("message")
  4. 'Create the e-mail server object
  5. Set objCDOSYSMail = Server.CreateObject("CDO.Message")
  6. Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
  7. 'Out going SMTP server
  8. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "MY_ISP_SMTP_SERVER_ADDRESS"
  9. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  10. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  11. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
  12. objCDOSYSCon.Fields.Update
  13. 'Update the CDOSYS Configuration
  14. Set objCDOSYSMail.Configuration = objCDOSYSCon
  15. objCDOSYSMail.From = "me@myhost.co.uk" ' the address you want the email to be from
  16. objCDOSYSMail.TO = to_field 'the address the mail is to be sent to
  17. objCDOSYSMail.Subject = "Subject goes here"
  18. objCDOSYSMail.HTMLBody = message
  19. objCDOSYSMail.Send
  20. 'Close the server mail object
  21. Set objCDOSYSMail = Nothing
  22. Set objCDOSYSCon = Nothing
  • pritesh_a
  • Graduate
  • Graduate
  • pritesh_a
  • Posts: 158
  • Loc: South London/UK

Post 3+ Months Ago

so i dont need a third page for the sent or fail confirmation??i.e. sent.asp

still not work!!!!!!
do i need to create the subject box in the first form???

DO u want a gmail account???
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

You don't need a third page. You don't need a subject box either. Post the error you are getting.

Thanks, but no thanks :D I've already got more emaila ccounts than I can keep track of :D
  • 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!
  • 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: 23473
  • 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: 23473
  • 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: 23473
  • 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 37 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
 
 

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