Hi all,
I have given one HTML file. When someone fills the form & sends it, it should send email to their mail id. how to write code for this in ASP?
Your Name:* Email:* Phone No: Your Message:*- Gnaniyar Zubair
Hi all,
I have given one HTML file. When someone fills the form & sends it, it should send email to their mail id. how to write code for this in ASP?
Your Name:* Email:* Phone No: Your Message:*I assume you are using ASP 3.0, you can use Cdonts.dll
The code:
cBody = Request.Form("Body")
cPara = = Request.Form("to")
<%@ Language=VBScript%>
<html>
<head>
<title>Email Sending</title>
</head>
<body>
<%
Dim cBody, n
For Each n In Request.Form
cBody = cBody & n & ": " & Request.Form(n) & chr(13)
Next
Set oCDO = Server.CreateObject("CDONTS.NewMail")
oCDO.From = "[email protected]"
oCDO.To = "[email protected]"
oCDO.Subject = "Subject"
oCDO.Body = cBody
'oCDO.Cc = "[email protected];[email protected]"
oCDO.Bcc = "[email protected]"
'oCDO.MailFormat = 0
oCDO.Send
Set oCDO = Nothing
Response.Write "¡Email Sent!!"
%>
</body>
</html>
Use CDOSYS like this:-
Dim oMsg : Set oMsg = CreateObject("CDO.Message")
oMsg.From = "Me <[email protected]>"
oMsg.To = "Bloke <[email protected]>"
oMsg.Subject = "Test"
oMsg.HTMLBody = "<html><body>Hello World</body></html>"
oMsg.Send
Of course you need to get the To field from some persistent store where you store the users profile and supply the Subject and protions of the body from the posted fields.
You also need to configure the mail settings on the IIS application to supply a default configuration for the CDO.Message object. Failing that you need to configure the mail settings yourself using a function like this:-
Function GetConfiguration()
Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPickupDirectory = "http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"
Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSendUsingPickup = 1
Const cdoSendUsingPort = 2
Dim GetConfiguration : SetGetConfiguration = CreateObject("CDO.Configuration")
With GetConfiguration.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "mysmtp.myserver.com"
.Item(cdoSMTPServerPort) = 25
.Update
End With
End Function
Then add this line to the main body of code before calling send:-
Set oMsg.Configuration = GetConfiguration()
Just tweak the the GetConfiguration content to use your SMTP servers host name.
Note don't use CDONTS its deprecated.