Search Tutorials
Option 3 - Setting up the ASP script to send mail with ASPThe following script shows you how to send mail with ASP - it works similar to the two methods shown above. This script is from a Popular Windows 2000 Hosting service called innerhost. The main difference between a PHP based mailing script and an ASP based mailing script is the use of a mailing object. Many Win NT/2K Hosts have the Smtpsvg.dll registered on their servers. If they do not, please check with the Host to see what sort of mail object they do use. The code below is pretty self-explanatory. On line 12, be sure to change “mail.innerhost.com” to the SMTP mail server that your host provides. Also make sure to change lines 7-10 to your Name, Email, Subject etc. This e-mail will work in the same manner as the previous two examples. 1) <?
2) FirstName = Request.form("FirstName")
3) Email = Request.form("Email")
4) Company = Request.form("Company")
5) ToComments = Request.form("ToComments")
6) HearAbout = Request.form("HearAbout")
7) strName = "Your Name"
8) strEmail = "YourEmail@YourSite.com"
9) strSubject = "Tutorial Request Example Email"
10) strBody = ToComments & HearAbout & Company
11) Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
12) Mailer.RemoteHost = "mail.innerhost.com"
13) Mailer.FromName = FirstName
14) Mailer.FromAddress = Email
15) Mailer.AddRecipient strName, strEmail
16) Mailer.Subject = (strSubject)
17) Mailer.BodyText = strBody
18) if Mailer.SendMail then
19) Response.Write "_root.Mail.EmailStatus=Complete - Your mail has been sent"
else
20) Response.Write "_root.Mail.EmailStatus=Failure - Your mail was not sent - errors"
21) Response.Write Mailer.Response
22) end if
23) ?>
Line 1 - Starts the ASP script Lines 2 to 6 - This captures the data sent with the header information from the post command and puts it into a format that the asp script can use. Lines 7 to 8 - Sets the Name and E-mail address to which you are sending this information to. Make sure to change this to your own name and e-mail if you are going to be receiving this e-mail (or to the person that is). Line 9 - This sets the subject line of the message that you are sending. Line 10 - Formats the contents of the inputted information into the Body of the Email. Line 11 - This sets the Mailing object, that enables the script to send the E-mail. This may be different, SMTPsvg.Mailer is the most common Mailing Object but can be different depending on your server. Line 12 - Make sure to change this according to your Host. Lines 13 to 17 - Sets up the e-mail and assigns each different E-mail field it's previously defined vale. Lines 18 to 22 - Just checks to see if the mail was sent - If it was it prints out a Complete/success message back to the Flash movie. If it was not successful then an error message is sent back to the flash movie. And that's about it with the ASP section - Remember that because of the wide variety of server setups and the ways that individual hosting services set up their server, this will not work all the time. I tried to give the most general widely used examples - but you may have to contact your host for further information.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|