Send Email

M

Miguel Dias Moura

Hello,

i am changing a web site from ASP to ASP.net.
I wrote some code using my old standard ASP code and some information from
my hosting service.

I want the email, with the form values, to be sent when the button OK is
pressed.

Should i place this script on the form page or on a new page? How can i send
the email when the button OK is pressed?

I am having problems in understanding how Private Sub Page_Load() works.
I think i didn't do any mistake in my script...i am using Advanced Intelect
AspNetEmail.

Can you help me out?

The script i am using is as follows:

<Script runat="server">

Private Sub Page_Load()

Dim msg As EmailMessage = New EmailMessage("localhost")

' Declare the variables for the form
Dim msgTo, msgFrom, msgName, msgSubject, msgMessage
' Make the variables equal to the form elements
msgTo = Request.Form("to")
mgsFrom = Request.Form("from")
msgName = Request.Form("name")
msgSubject = Request.Form("subject")
mgsMessage = Request.Form("message")

' Set the email type
Mail.IsHTML = True

' Set the from address
msg.FromAddress = msgFrom

' Set the to address
msg.To = msgTo

' Set the from name
msg.FromName = msgName

' Set the email subject
msg.Subject = msgSubject

' Set the email message
msg.Body = "<html><head><style type='text/css'>body {font-family:
Verdana, Arial, Helvetica, sans-serif; font-size: 11px;color: #333333;
background-color: #FFFFFF;}</style></head><body>" &_
"<strong>Formulário de Contacto (bonsAlunos.com)</strong>" &_
"<br><br><strong>&nbsp;&nbsp;» From: </strong>" & msgFrom &_
"<br><strong>&nbsp;&nbsp;» Nome: </strong>" & msgNome &_
"<br><br><strong>&nbsp;&nbsp;» To: </strong>" & msgTo &_
"<br><br><strong>&nbsp;&nbsp;» Assunto: </strong>" & msgSubject &_
"<br><br><strong>Mensagem</strong>" &_
"<br><br> " & msgMessage &_
"</body></html>"

' Send the email
On Error Resume Next ' Catch Errors
msg.Send()
If Err <> 0 Then ' An Error Occurred
Response.Redirect("status.aspx?local=contactErr")
else
Response.Redirect("status.aspx?local=contactOk")
End If

End Sub

</script>


Thank You,
Miguel
 
J

Jason MacKenzie

If I unnderstood your question correctly, place the code to send the email
in the click event of your OK button.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top