Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Send form values using AspNetEmail. Can you help me out? Thank You.

Reply
Thread Tools

Send form values using AspNetEmail. Can you help me out? Thank You.

 
 
Miguel Dias Moura
Guest
Posts: n/a
 
      04-01-2004
Hello,



Can you help me out in making this work? What I want is as simple as sending
form values to an email.



The code I am using is the following:



<Script runat="server">



Private Sub Page_Load()



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

Dim msgTo, msgFrom, msgName, msgSubject, msgMessage



msgTo = Request.Form("to")

msgFrom = Request.Form("from")

msgName = Request.Form("name")

msgSubject = Request.Form("subject")

msgMessage = Request.Form("message")



' Set the email type

msg.BodyFormat = MailFormat.Html



' Set the from address

msg.FromAddress = msgFrom



' Set the to address

msg.To = msgTo



' Set the from name

msg.FromName = msgFrom



' 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: </style></head><body>" &_

"<strong>New Message</strong>" &_

"<br><strong>From: </strong>" & msgFrom &_

"<br><strong>Name: </strong>" & msgName &_

"<br><strong>To: </strong>" & msgTo &_

"<br><strong>Subject: </strong>" & msgSubject &_

"<br><strong>Message Text</strong>" &_

"<br> " & msgMessageField &_

"</body></html>"



' Internal Exceptions

msg.ThrowException = False



' Logging and LogBody

msg.Logging=false

msg.LogBody = false



' Sends Message

If msg.Send() Then

' Redirects to error page

Response.Redirect("status.aspx?result=contactErr")

Else

' Redirects to confirmed page

Response.Redirect("status.aspx?result=contactOk")

End If



End Sub



</script>



I really would appreciate if you could send me a working example using my
code. I am trying to make it work for 1 week and until now I had no luck.

The form has 5 text inputs: to, from, name, subject and message AND a button
which when pressed should send the form values in the email.

I tryied to comment everything I could think of. I am working in ASP.net /
VB.



Thank You Very Much,

Miguel Moura



 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmlsbCBCb3Jn?=
Guest
Posts: n/a
 
      04-01-2004
Miguel

You don't say exactly what doesn't work with yours (empty form fields, no mail message, etc.), but anyway I would do it in the code-behind (not in the html). Here's a simplified example

Private Sub btnSubmit_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles btnSubmit.Clic

' Send the message..
Dim msg As New Mail.MailMessag
msg.To = txtTo.Tex
msg.From = txtFrom.Tex
msg.Body = txtMessage.Tex

Mail.SmtpMail.SmtpServer = "My Mail Server
Mail.SmtpMail.Send(msg

End Su

The form itself just has txtTo, txtFrom, and txtMessage as the IDs of input fields and btnSubmit as the ID of the submit button

If you're not getting any messages sent at all, you might check your smtp server. I don't know all the ins and outs, but do know that you can only use localhost if your box is configured to send mail (mine isn't, and I think it also has to do with the o/s)

hth

Bil

----- Miguel Dias Moura wrote: ----

Hello



Can you help me out in making this work? What I want is as simple as sendin
form values to an email



The code I am using is the following



<Script runat="server"



Private Sub Page_Load(



Dim msg As EmailMessage = New EmailMessage("localhost"

Dim msgTo, msgFrom, msgName, msgSubject, msgMessag



msgTo = Request.Form("to"

msgFrom = Request.Form("from"

msgName = Request.Form("name"

msgSubject = Request.Form("subject"

msgMessage = Request.Form("message"



' Set the email typ

msg.BodyFormat = MailFormat.Htm



' Set the from addres

msg.FromAddress = msgFro



' Set the to addres

msg.To = msgT



' Set the from nam

msg.FromName = msgFro



' Set the email subjec

msg.Subject = msgSubjec



' Set the email messag

msg.Body = "<html><head><style type='text/css'>body {font-family
Verdana, Arial, Helvetica, sans-serif; font-size: 11px;color: #333333
background-color: </style></head><body>" &

"<strong>New Message</strong>" &

"<br><strong>From: </strong>" & msgFrom &

"<br><strong>Name: </strong>" & msgName &

"<br><strong>To: </strong>" & msgTo &

"<br><strong>Subject: </strong>" & msgSubject &

"<br><strong>Message Text</strong>" &

"<br> " & msgMessageField &

"</body></html>



' Internal Exception

msg.ThrowException = Fals



' Logging and LogBod

msg.Logging=fals

msg.LogBody = fals



' Sends Messag

If msg.Send() The

' Redirects to error pag

Response.Redirect("status.aspx?result=contactErr"

Els

' Redirects to confirmed pag

Response.Redirect("status.aspx?result=contactOk"

End I



End Su



</script



I really would appreciate if you could send me a working example using m
code. I am trying to make it work for 1 week and until now I had no luck

The form has 5 text inputs: to, from, name, subject and message AND a butto
which when pressed should send the form values in the email

I tryied to comment everything I could think of. I am working in ASP.net
VB



Thank You Very Much

Miguel Moura




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing form values from one page to other. Please, help me out. Thank You. Miguel Dias Moura ASP .Net 4 05-25-2004 12:19 AM
Can you persist table cell values like you do with form field values? Richard Dixson ASP .Net 2 05-18-2004 01:11 PM
Can you persist table cell values like you can do with form field values? Richard Dixson ASP .Net 1 05-18-2004 03:47 AM
Thank You CJ, Thank Mike! mytho Computer Support 7 11-23-2003 06:50 AM
Thank You CJ, Thank Mike! mytho Computer Support 0 11-22-2003 01:35 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57