% '******************************************************* '* ASP 101 Sample Code - http://www.asp101.com * '* * '* This code is made available as a service to our * '* visitors and is provided strictly for the * '* purpose of illustration. * '* * '* Please direct all inquiries to webmaster@asp101.com * '******************************************************* %> <% Dim strTo, strSubject, strBody 'Strings for recipient, subject, boby Dim objCDOMail 'The CDO object 'First we'll read in the values entered strTo = Request.Form("to") 'These would read the message subject and body if we let you enter it 'strSubject = Request.Form("subject") 'strBody = Request.Form("body") strSubject = "Sample E-mail sent from ASP 101!" ' This is multi-lined simply for readability strBody = "This message was sent from a sample at http://www.asp101.com. " strBody = strBody & "It is used to show people how to send e-mail from an " strBody = strBody & "Active Server Page. If you did not request this " strBody = strBody & "e-mail yourself, your address was entered by one of " strBody = strBody & "our visitors. We do not store these e-mail addresses." strBody = strBody & " Please address all concerns to webmaster@asp101.com." ' Some spacing: strBody = strBody & vbCrLf & vbCrLf strBody = strBody & "This was sent to: " ' A lot of people have asked how to use form data in the emails so ' I added this line to the sample as an example of incorporating form ' data in the body of the email. strBody = strBody & Request.Form("to") ' A final carriage return for good measure! strBody = strBody & vbCrLf 'Ok we've got the values now on to the point of the script. 'We just check to see if someone has entered anything into the to field. 'If it's equal to nothing we show the form, otherwise we send the message. 'If you were doing this for real you might want to check other fields too 'and do a little entry validation like checking for valid syntax etc. ' Note: I was getting so many bad addresses being entered and bounced ' back to me by mailservers that I've added a quick validation routine. If strTo = "" Or Not IsValidEmail(strTo) Then %>
<% Else ' Create an instance of the NewMail object. Set objCDOMail = Server.CreateObject("CDONTS.NewMail") ' Set the properties of the object '*********************************************************** ' PLEASE CHANGE THESE SO WE DON'T APPEAR TO BE SENDING YOUR ' EMAIL. WE ALSO DON'T WANT THE EMAILS TO GET SENT TO US ' WHEN SOMETHING GOES WRONG WITH YOUR SCRIPT... THANKS '*********************************************************** ' This syntax works fine 'objCDOMail.From = "webmaster@asp101.com" ' But this gets you the appearance of a real name! objCDOMail.From = "ASP 101 Webmaster