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. .To = "[email protected]"
  14. .Subject = Request.Form("subject")
  15. .TextBody = Request.Form("body")
  16. '.HTMLBody = Request.Form("body") 'use HTML instead of plain text
  17.  
  18. err.clear
  19. on error resume next
  20. .From = Request.Form("fromAddress")
  21. .Send
  22. on error goto 0
  23. if err.number <> 0 then 'fromAddress isn't a valid email address; send it from your generic "no reply" address instead
  24. .From = """No-Reply"" <[email protected]>"
  25. .Send
  26. end if
  27. end with
  28. set email = Nothing
  29. end if
  30. %>
  31.  
  32. <html>
  33. <head>
  34.  
  35. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  36.  
  37. <title>Send Me An Email</title>
  38.  
  39. </head>
  40. <body>
  41.  
  42. <h1>Send me an email</h1>
  43.  
  44. <form action="sendMeAnEmail.asp" method="post">
  45.  
  46. <table><tbody>
  47. <tr><td><label for="fromAddress">Your email address: </label></td>
  48. <td><input type="text" id="fromAddress" name="fromAddress"></td></tr>
  49. <tr><td><label for="subject">Subject: </label></td>
  50. <td><input type="text" id="subject" name="subject"></td></tr>
  51. <tr><td><label for="body">Body: </label></td>
  52. <td><textarea id="body" name="body"></textarea></td></tr>
  53. <tr><td></td>
  54. <td><input type="submit" name="submit" value="Send Email"></td></tr>
  55. </tbody></table>
  56.  
  57. </form>
  58.  
  59. </body>
  60. </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.