Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to send form data straight to an email address? 1

Status
Not open for further replies.

RMcCallan

Programmer
Sep 20, 2010
62
GB
I currently have a 'contact us' form on a website I am designing, the client wants this information to be sent through to their inbox straight away once 'submit' is clicked. Is this possible or will it have to go into the sql database first and then sent from there? Any replied appreciated!

Thanks,
Rebecca
 
Ok cool, I'm quite new to this so how would I then put that code into VWD2010 (I'm using html primarily). Thanks for the reply.

Thanks,
Rebecca
 
You will need to use an .aspx page with a code-behind file and reference the namespace mentioned by Mark.
 
Yes I do understand that but the reason that I asked this question is because I don't know what code to write... if I knew I would have written it myself and not asked these questions... also I've looked at those tutorials before and I can't find anything which would appear to help me with this...

Thanks,
Rebecca
 
Yes I do understand that but the reason that I asked this question is because I don't know what code to write... if I knew I would have written it myself and not asked these questions... also I've looked at those tutorials before and I can't find anything which would appear to help me with this...
In that case I'm not sure why you don't know what code to write. The first link I gave you has a simple example of sending an email. You can simply copy & paste that function into your project and call the function.

Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
asp.net isn't code, it's a framework written on top of the .net framework. on top of asp.net you have the webforms view engine and various MVC frameworks.

if you think asp.net code is the IDE wizards, or webforms markup. well that's just the tip of the ice burg.

I would recommend learning the asp.net pipeline and the webforms page life cycle. this will give you a solid foundation to understand what's happening when you render a webpage and where to place your code.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
that wasn't asp.net code though
If you are to start writing asp.net websites, you need to understand the difference between server-side and client-side code.

That is the original reason I had previosly posted a link to the getting started articles on asp.net, as they will show you how to write an asp.net website. You have to write server-side code to send a html response to the client and the email link was an example of the server-side code you have to write to send your email.



Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
I didn't think it was code, what confused me was when ca8msm said that I 'have to write some ASP.NET code'. And I have pretty much finished the website without knowing EXACTLY what asp.net is etc. I just haven't used any VB code in it before and was wondering how you put it in... Anyway... if you would still like to help me, please? I have created the class and put in the email coding etc but now I am unsure of how to call this from the 'submit' button on the contact us page, any pointers?

Thanks,
Rebecca
 
that's what i thought. it's very easy to create an application without knowing how or what you actually did.

research the asp.net pipeline and the webforms page lifecycle. from there you should be able to figure out how to put a button on a page and hook into the click event. once in the click event you can send an email.

technically you don't need to know the pipeline or the page life cycle, but it really does help to understand what your using to know how your application is behaving.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Did you watch any of the videos from the getting started link I gave you? The intro to ASP.NET controls video which is in the first section of the Web Forms examples shows you exactly how to create a button and use the server-side event. You just need to follow that example and call the function I gave you.

Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
Ok... so I have now watched that video and done exactly the same but with the code you gave me... it still doesn't work.

Thanks,
Rebecca
 
I don't get an email. I have tried moving this bit around as I'm not sure how you would put a public sub into a protected sub as I've never used a protected sub before, Are you supposed to replace it? Because this doesn't work either. Currently the coding in the Contact.aspx.vb document consists of the following:
Code:
 Imports System.Net.Mail
Partial Class Contact
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    End Sub
    Public Sub sendEmail(ByVal EmailAddress As String, ByVal Subject As String, ByVal EmailBody As String, ByVal FromAddress As String)
        Dim Message As New MailMessage(FromAddress, EmailAddress, Subject, EmailBody)
        Dim smtp As New SmtpClient("127.0.0.1")
        Dim NetworkCredentials As New System.Net.NetworkCredential

        NetworkCredentials.UserName = "UserName"
        NetworkCredentials.Password = "Password"
        smtp.Credentials = NetworkCredentials
        smtp.Send(Message)
    End Sub
End Class

The username and password are in there when I try did I just didn't want to broadcast my username and password on here...

Thanks,
Rebecca
 
You haven't called the function from your Button Click. e.g.
Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        sendEmail("you@here.com","My Subject","My Body","me@there.com")
    End Sub
and if you still don't get an email, see my earlier comments about having an SMTP server setup or read the comments in the sendEmail function about writing the email to a text file during testing.

Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
Ok that makes sense. I have put that link in now and it had started erroring on it. I presumed that where you have "you@here.com" etc. it should be replaced by the ID's of my text boxes? So mine says
Code:
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        sendEmail("EmailAddress", "Subject", "EmailBody", "FromAddress")

    End Sub
What am I doing wrong now?

Thanks for your help by the way.

Thanks,
Rebecca
 
If you have the details in a text box then you need to reference the relevant TextBoxes e.g.
Code:
   Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        sendEmail(Textbox1.Text, Textbox3.Text, Textbox3.Text, Textbox4.Text)
    End Sub
etc...



Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top