![]() | การส่ง mail ด้วย asp | ![]() |
| ข้อควรทราบ |
|
|
โปรแกรม asp สั้น ๆ เพื่อส่ง mail (แต่แก้ไขค่าอะไรไม่ได้ เมื่อ run แล้วจะส่งทันที) |
| ผลลัพธ์ที่ต้องการ | Source code ของ sndmailw.asp |
| Mail จะส่งไปถึง webmaster@thaiall.com และ burin@yonok.ac.th โดยจ่าหน้าซองผู้ส่งว่า test@thaiabc.com จะส่งคำว่า hello this is subject เป็นคำที่อยู่ในส่วนของ subject และ This is the messages. เป็นข้อความ |
<%
Set SMTPObj = CreateObject("WebHostMeMail.SMTP")
SMTPObj.SMTPServer = "Mail.webhostme.com"
SMTPObj.ToAdd = "webmaster@thaiall.com,burin@yonok.ac.th"
SMTPObj.FromAdd = "test@thaiabc.com"
SMTPObj.Subject = "hello this is subject"
SMTPObj.Body = "This is the messages."
SMTPObj.Connect
result = SMTPObj.EMail
Response.write "Sent " & result
SMTPObj.Quit
%>
|
|
ฟอร์มที่เขียนใน html เพื่อสั่งให้ส่งค่า ซึ่งสามารถระบุผู้รับ และ message ได้ |
| ผลลัพธ์ที่ต้องการ | Source code ของ sndmail.htm |
<body> <form method=post action=http://thaiall.webhostme.com/sndmail.asp> To email : <input type="text" name=toadd><br> From email : <input type="text" name=fromadd><br> Subject : <input type="text" name=subj><br> <textarea name=body cols=40 rows=6></textarea><br> <input type=submit value=send> <input type=reset value=reset><br> </form> </body> |
|
โปรแกรม asp ที่ใช้รับค่าจาก form ทำหน้าที่ส่ง mail ไปให้ผู้รับที่กำหนด |
| ผลลัพธ์ที่ต้องการ | Source code ของ sndmail.asp |
|
โปรแกรมนี้จะรับค่าจากตัวแปร 4 ตัว แล้วนำค่าทั้ง 4 ไปเป็นค่ากำหนดในการส่ง mail คือ toadd, fromadd, subj และ body |
<%
Set SMTPObj = CreateObject("WebHostMeMail.SMTP")
SMTPObj.SMTPServer = "Mail.webhostme.com"
SMTPObj.ToAdd = request.form("toadd")
SMTPObj.FromAdd = request.form("fromadd")
SMTPObj.Subject = request.form("subj")
SMTPObj.Body = request.form("body")
SMTPObj.Connect
result = SMTPObj.EMail
Response.write "Sent " & result
SMTPObj.Quit
%>
|
| แบบฝึกหัด |
|