Forums

ASP

This topic is locked

CDONTS or CDOSYS?? Please help!!!

Posted 24 Nov 2003 13:04:25
1
has voted
24 Nov 2003 13:04:25 Billy Griffiths posted:
I want to create a page that submits to e-mail. A form gets submitted to the page below. This will not work. Can anyone help? Is there a tutorial that will help me with this?

<%
DIM strEmail, strName, strComments, mail, reply, objMail
strEmail = request.form("Email"
strName = request.form("Name"
strComments = request.form("Comments"

mail = " "
reply = request.form("Email"
Set objMail = Server.CreateObject("CDONTS.NewMail"
objMail.From = reply
objMail.Subject = "MAIL FROM CLIENT"
objMail.To = mail
objMail.Body = "Email: " & strEmail & vbCrLf & _
"Name: " & strName & vbCrLf & _
"Comments: " & vbCrLf & strComments

objMail.Send
Set objMail = nothing
%>

<P>
<%
Response.Write(strName)
%></P>

<P>Thank you for emailing me.</P>



Xcalibur
Cape Town - South Africa

Replies

Replied 24 Nov 2003 14:30:27
24 Nov 2003 14:30:27 Dave Thomas replied:
This should do it.

<pre id=code><font face=courier size=2 id=code>
&lt;%@LANGUAGE="VBSCRIPT"%&gt;
&lt;%
Response.Buffer = True

Dim strBody
Dim objCDOMail
Dim strMyEmailAddress
Dim strReturnEmailAddress

strMyEmailAddress = " "


'Read in the users e-mail address
strReturnEmailAddress = Request.Form("Email"

'Initialse strBody string with the body of the e-mail
strBody = "&lt;h3&gt;E-mail sent from THE BLAH BLAH SITE&lt;/h3&gt;"
strBody = strBody & "&lt;br&gt;&lt;br&gt;Hello."
strBody = strBody & "&lt;br&gt;&lt;br&gt;Some text"
strBody = strBody & "&lt;br&gt;Mail from: " & Request.Form("Name"
strBody = strBody & "&lt;br&gt;Email Address " & Request.Form("Email"
strBody = strBody & "&lt;hr&gt;"
strbody = strBody & "&lt;b&gt;Comments/Enquiry::&lt;/b&gt;&lt;br&gt;"
strBody = strBody & Replace(Request("Comments", VbCrLf, "&lt;BR&gt;"
strBody = strBody & "&lt;br&gt;&lt;br&gt;"
strBody = strBody & "&lt;hr&gt;"
strBody = strBody & "Your email footer info goes here"
' THE BODY OF EMAIL COULD GO ON FOREVER, MAKE IT UP AS YOU WISH.

'Check to see if the user has entered an e-mail address and that it is a valid address otherwise set the e-mail address to your own otherwise the e-mail will be rejected
If Len(strReturnEmailAddress) &lt; 5 OR NOT Instr(1, strReturnEmailAddress, " " = 0 OR InStr(1, strReturnEmailAddress, "@", 1) &lt; 2 OR InStrRev(strReturnEmailAddress, "." &lt; InStr(1, strReturnEmailAddress, "@", 1) Then

'Set the return e-mail address to your own
strReturnEmailAddress = strMyEmailAddress
End If


'Send the e-mail

'Create the e-mail server object
Set objCDOMail = Server.CreateObject("CDONTS.NewMail"

'Who the e-mail is from (this needs to have an e-mail address in it for the e-mail to be sent)
objCDOMail.From = Request.Form("name" & " &lt;" & strReturnEmailAddress & "&gt;"

'Who the e-mail is sent to
objCDOMail.To = strMyEmailAddress

'Set the subject of the e-mail
objCDOMail.Subject = "MAIL FROM CLIENT"

'Set the e-mail body format (0=HTML 1=Text)
objCDOMail.BodyFormat = 0

'Set the mail format (0=MIME 1=Text)
objCDOMail.MailFormat = 0

'Set the main body of the e-mail
objCDOMail.Body = strBody

'Importance of the e-mail (0=Low, 1=Normal, 2=High)
objCDOMail.Importance = 1

'Send the e-mail
objCDOMail.Send

'Close the server object
Set objCDOMail = Nothing
%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Thank you for sending us your comments&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p align="center"&gt;Thank you for Emailing me, I will be in touch shortly.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;

</font id=code></pre id=code>

Regards,
Dave

UD4 | Flash 5/MX | Studio MX | SQL | Access | ASP/VBScript | XP-Pro
Replied 24 Nov 2003 15:00:51
24 Nov 2003 15:00:51 Billy Griffiths replied:
I have tried this but still no luck. I am running Win 2000 with IIS 5.0. Can this be why? It gives me the "successfully sent" message, but no e-mail in my mailbox. ish!!

Xcalibur
Cape Town - South Africa
Replied 24 Nov 2003 19:00:43
24 Nov 2003 19:00:43 Dave Thomas replied:
you sending the form from a web page? or a local machine running iis 5.0?

that code works on a web page, i use it myself, all i did was modify the body and email info.

Regards,
Dave

UD4 | Flash 5/MX | Studio MX | SQL | Access | ASP/VBScript | XP-Pro
Replied 25 Nov 2003 05:46:41
25 Nov 2003 05:46:41 Dave Blohm replied:
On Win2K do the following:

&lt;%
Set objCDO = Server.CreateObject("CDO.Message"
With objCDO
.To = " "
'.Cc =
'.Bcc =
.From = request.form("Name" & "&lt;" & request.form("Email" & "&gt;"
.Subject = "Mail From Client"
.TextBody = request.form("Comments"
'.HTMLBody=
.Send
End With
Set objCDO = Nothing

Response.Write request.form("Name" & ",&lt;br&gt;&lt;br&gt;Thank you for emailing me."
%&gt;

Unless there is a specific reason for using HTML as the vehicle for your email (such as including images) there is no reason to send anything other than plain text. I use this script on many many apps and it works like a charm...

Hope this helps,

Doc
Rangewalk Digital Studios

Edited by - on 25 Nov 2003 05:49:10

Reply to this topic