|
ตัวอย่าง
การเขียน Script ทำการ List records จาก database โดยไม่ใช้
ODBC connection (DSNLESS)
<%
'initialise objects and variables
dim conn, strsql, rsuser, strMDBPath
set conn=server.createobject("ADODB.Connection")
set rsuser=server.createobject("ADODB.Recordset")
strMDBpath = Server.MapPath("..\private\northwind.mdb")
'direct connection
conn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE="
& strMDBPath
strsql = "select top 10 (city) from customers"
rsuser.open strsql,conn,1,2
'iterate thro recordset
Do while not rsuser.eof
response.write rsuser("city") & "<br>"
rsuser.movenext
Loop
'close resources used
rsuser.close
conn.close
'clean up
set rsuser=nothing
set conn=nothing
%>
--------------------------------------------------------------------------------------------------------------------
ตัวอย่าง
การเขียน Script ส่ง EMail แบบ JMailForm
Code ในส่วนของ HTML
<html>
<head>
<title>emailform</title>
</head>
<body>
<form method="post" action="SendMail.asp">
Complete this form and click the Submit button.
<br><br>
Your name<br>
<input type="text" size="25" name="name"><br>
Your email<br>
<input type="text" size="25" name="email"><br>
Recipient email<br>
<input type="text" size="25" name="recipient"><br>
State your business<br>
<select name="subject" size="1">
<option value="help">help
<option value="tips">tips
<option value="other">other
</select>
<br> Enter your question<br>
<textarea name="body" cols="40" rows="15"
wrap="PHYSICAL"></textarea>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Code ในส่วนของ ASP
<%@LANGUAGE = VBSCRIPT%>
<html>
<body>
<%
' Get the form data
name = Request.Form("name")
senderEmail = Request.Form("email")
subject = "Regarding " & Request.Form("subject")
recipient = Request.Form("recipient")
body = Request.Form("body")
strReferer = request.servervariables("HTTP_REFERER")
strServer = Replace(request.servervariables("SERVER_NAME"),"www.","")
strSMTPServer = "smtp." & strServer
' check referer
intComp = inStr(strReferer, strServer)
If intComp > 0 Then
blnSpam = False
Else
' Spam Attempt Block
blnSpam = True
End If
' Create the JMail message Object
set msg = Server.CreateOBject( "JMail.SMTPMail" )
' Set logging to true to ease any potential
debugging
' And set silent to true in case you wish to handle the errors yourself
msg.Logging = true
msg.silent = true
' Enter the sender data
msg.From = senderEmail
msg.FromName = name
' Note that as addRecipient is a method
and not
' a property, you do not use an equals ( = ) sign
msg.AddRecipient recipient
' The subject of the message
msg.Subject = subject
' And the body
msg.body = body
' Now send the message, using the indicated
mailserver
If NOT blnSpam Then
if not msg.Send(strSMTPServer ) then
Response.write "<pre>" & msg.log & "</pre>"
else
Response.write "Message sent successfully!"
end if
end if
' Clear the object
set msg = nothing
%>
</body>
</html>
NOTE: Do not forget to clear the mail
object at the end of the script.
Warning
The JMail component use SMTP (Simple Mail Transfer Protocol), and
you should be aware that all Fasthosts' SMTP servers have filters
which ensure that either the 'to' or 'from' address relates to one
of your domains hosted by Hostpromotion
--------------------------------------------------------------------------------------------------------------------
ตัวอย่าง การเขียน Script ส่ง EMail แบบ CDONTS
Code ในส่วนของ ASP
<%
dim objmail ' create variable
set objmail = server.createobject("CDONTS.Newmail") '
create object
objmail.to = "you@yourcompany.com"
' recipient
objmail.from = "me@mycompany.com" ' sending address
objmail.subject = "This is a test mail" ' set the subject
objmail.date = "This is a test mail generated by CDO for NTS"
' set the body of the message
objmail.send ' send the mail
set objmail = nothing ' clear the object
%>
NOTE: Do not forget to clear the mail
object at the end of the script.
------------------------------------------------------------------------------------------------------------------
สามารถ Download Script ต่างๆได้ที่นี่
้http://www.thaicheaphost.com/download/
|