Posted By

wizard04 on 07/29/08


Tagged

email ASP vbscript


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

nelda751
ckayra
benrudolph
nickian


Send Email


 / Published in: ASP
 

Send an email from the server.

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <%
  3. if Request.Form("submit") = "Send Email" then
  4. dim email
  5. set email = Server.CreateObject("CDO.Message")
  6. with email
  7. .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  8. .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
  9. 'if "localhost" doesn't work, use your mail server instead
  10. '.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.example.com"
  11. .Configuration.Fields.Update
  12.  
  13. .Subject = Request.Form("subject")
  14. .TextBody = Request.Form("body")
  15. '.HTMLBody = Request.Form("body") 'use HTML instead of plain text
  16.  
  17. err.clear
  18. on error resume next
  19. .From = Request.Form("fromAddress")
  20. .Send
  21. on error goto 0
  22. if err.number <> 0 then 'fromAddress isn't a valid email address; send it from your generic "no reply" address instead
  23. .From = """No-Reply"" <[email protected]>"
  24. .Send
  25. end if
  26. end with
  27. set email = Nothing
  28. end if
  29. %>
  30.  
  31. <html>
  32. <head>
  33.  
  34. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  35.  
  36. <title>Send Me An Email</title>
  37.  
  38. </head>
  39. <body>
  40.  
  41. <h1>Send me an email</h1>
  42.  
  43. <form action="sendMeAnEmail.asp" method="post">
  44.  
  45. <table><tbody>
  46. <tr><td><label for="fromAddress">Your email address: </label></td>
  47. <td><input type="text" id="fromAddress" name="fromAddress"></td></tr>
  48. <tr><td><label for="subject">Subject: </label></td>
  49. <td><input type="text" id="subject" name="subject"></td></tr>
  50. <tr><td><label for="body">Body: </label></td>
  51. <td><textarea id="body" name="body"></textarea></td></tr>
  52. <tr><td></td>
  53. <td><input type="submit" name="submit" value="Send Email"></td></tr>
  54. </tbody></table>
  55.  
  56. </form>
  57.  
  58. </body>
  59. </html>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: wizard04 on November 1, 2009

Updated to make it a working example.

You need to login to post a comment.