System generated email...

Discussion in 'ASP General' started by Ken D., Jun 8, 2006.

  1. Ken D.

    Ken D. Guest

    I have an asp page that collects data on referrals. The user inputs the
    information and selects the rep to receive the referral. My data is being
    saved to a backend database (SQL) and the user is receiving a confirmation
    page after hitting the Submit button. Now, what I need is a way to have an
    email sent to the rep that is selected in the drop down list on the asp form.
    I have a SQL table containing the reps and corresponding email addresses.

    Is it even possible to achieve what I am trying to do? I am trying to avoid
    sending a blanket email to a single address and having someone filter them
    from there.

    HELP...
     
    Ken D., Jun 8, 2006
    #1
    1. Advertising

  2. Ken D.

    Rob Meade Guest

    "Ken D." wrote ...

    > Is it even possible to achieve what I am trying to do? I am trying to
    > avoid
    > sending a blanket email to a single address and having someone filter them
    > from there.


    Hi Ken,

    If I'm following you correctly then yes...


    In your code that handles the form being submitted...

    strRepID = request.form("repid") ' replace this with the name of your
    drop down list - I'm assuming it contains an ID for the rep?

    ' run a query against your database to return the email address - a
    stored procedure to return it based on the rep id might be nice
    ' strEmailAddress = RS("RepsEmailAddress")

    ' send the email using the above string in the TO property
    ' (see this article for an example on sending CDO emails
    http://www.aspfaq.com/show.asp?id=2339)

    Hope this is of some help...you could tart it up a bit by doing some checks
    to see if you returned a reps details or not and displaying a suitable
    message if not, in addition your stored procedure could also get the reps
    name and you could then on your confirmation page say "An email has been
    sent to Mr A Rep" etc etc..

    Regards

    Rob
     
    Rob Meade, Jun 9, 2006
    #2
    1. Advertising

  3. Ken D.

    Ken D. Guest

    Rob,

    Thanks for the reply. Not being a programmer, sometimes I am a bit
    challenged. Let me ask you this. I have an asp page that I built in
    Frontpage 2002 that upon submit, sends data to a SQL database and provides a
    confirmation to the user. I want to initiate the email to the rep selected
    in a combo box on the asp form at the same time the submit button is
    selected. I have a stored procedure that returns the last entered rep (and
    it works great). My question is, where do I insert your code in order to get
    it to fire at the submit event. I understand the script goes on my asp page
    but where does the strRepID and strEmailAddress go and how does it get called.

    Sorry to sound so confusing with this. Any help would be appreciated.

    Ken

    "Rob Meade" wrote:

    > "Ken D." wrote ...
    >
    > > Is it even possible to achieve what I am trying to do? I am trying to
    > > avoid
    > > sending a blanket email to a single address and having someone filter them
    > > from there.

    >
    > Hi Ken,
    >
    > If I'm following you correctly then yes...
    >
    >
    > In your code that handles the form being submitted...
    >
    > strRepID = request.form("repid") ' replace this with the name of your
    > drop down list - I'm assuming it contains an ID for the rep?
    >
    > ' run a query against your database to return the email address - a
    > stored procedure to return it based on the rep id might be nice
    > ' strEmailAddress = RS("RepsEmailAddress")
    >
    > ' send the email using the above string in the TO property
    > ' (see this article for an example on sending CDO emails
    > http://www.aspfaq.com/show.asp?id=2339)
    >
    > Hope this is of some help...you could tart it up a bit by doing some checks
    > to see if you returned a reps details or not and displaying a suitable
    > message if not, in addition your stored procedure could also get the reps
    > name and you could then on your confirmation page say "An email has been
    > sent to Mr A Rep" etc etc..
    >
    > Regards
    >
    > Rob
    >
    >
    >
     
    Ken D., Jun 9, 2006
    #3
  4. Ken D.

    Mike Brind Guest

    If you think about the logic flow of your process, it should be fairly
    obvious. You need the rep's email address before you can send an email
    to him/her, right? So the email generation code has to go at some
    point after the code that successfully retrieves this information from
    your database.

    You have three actions to perform after you have retrieved the rep
    info:
    1. Send an email
    2. Write to the db
    3. Display a confirmation page.

    I can't see that it matters in which order you code these actions.
    None of them are dependent on the other, but all are dependent on
    successful validation of the information submitted in the form.

    --
    Mike Brind

    Ken D. wrote:
    > Rob,
    >
    > Thanks for the reply. Not being a programmer, sometimes I am a bit
    > challenged. Let me ask you this. I have an asp page that I built in
    > Frontpage 2002 that upon submit, sends data to a SQL database and provides a
    > confirmation to the user. I want to initiate the email to the rep selected
    > in a combo box on the asp form at the same time the submit button is
    > selected. I have a stored procedure that returns the last entered rep (and
    > it works great). My question is, where do I insert your code in order to get
    > it to fire at the submit event. I understand the script goes on my asp page
    > but where does the strRepID and strEmailAddress go and how does it get called.
    >
    > Sorry to sound so confusing with this. Any help would be appreciated.
    >
    > Ken
    >
    > "Rob Meade" wrote:
    >
    > > "Ken D." wrote ...
    > >
    > > > Is it even possible to achieve what I am trying to do? I am trying to
    > > > avoid
    > > > sending a blanket email to a single address and having someone filter them
    > > > from there.

    > >
    > > Hi Ken,
    > >
    > > If I'm following you correctly then yes...
    > >
    > >
    > > In your code that handles the form being submitted...
    > >
    > > strRepID = request.form("repid") ' replace this with the name of your
    > > drop down list - I'm assuming it contains an ID for the rep?
    > >
    > > ' run a query against your database to return the email address - a
    > > stored procedure to return it based on the rep id might be nice
    > > ' strEmailAddress = RS("RepsEmailAddress")
    > >
    > > ' send the email using the above string in the TO property
    > > ' (see this article for an example on sending CDO emails
    > > http://www.aspfaq.com/show.asp?id=2339)
    > >
    > > Hope this is of some help...you could tart it up a bit by doing some checks
    > > to see if you returned a reps details or not and displaying a suitable
    > > message if not, in addition your stored procedure could also get the reps
    > > name and you could then on your confirmation page say "An email has been
    > > sent to Mr A Rep" etc etc..
    > >
    > > Regards
    > >
    > > Rob
    > >
    > >
    > >
     
    Mike Brind, Jun 9, 2006
    #4
  5. Ken D.

    Ken D. Guest

    Mike,

    I found the following code which appears to solve my problem but I am
    getting a type mismatch error at the Response.Write(ParseBody(strBody)) line.

    Here is the code:
    **********************************************
    <html>

    <head>

    <%
    Function ParseBody(strText)
    strText = Replace(strText, Chr(13), "<br>")
    ParseBody = strText
    End Function

    Dim myConnString
    Dim myConnection
    Dim mySQL

    myConnString = Application("Sample_ConnectionString")
    Set myConnection = Server.CreateObject("ADODB.Connection")
    myConnection.Open myConnString

    mySQL= "INSERT INTO Employees "
    mySQL= mySQL & "(FirstName,LastName,Address,City,Region,PostalCode) "
    mySQL= mySQL & "VALUES ('" & Request.Form("FirstName") & "','"
    mySQL= mySQL & Request.Form("LastName") & "'"
    mySQL= mySQL & ",'" & Request.Form("Address") & "'"
    mySQL= mySQL & ",'" & Request.Form("City") & "','"
    mySQL= mySQL & Request.Form("Region") & "','"
    mySQL= mySQL & Request.Form("PostalCode") & "')"

    myConnection.Execute mySQL
    myConnection.Close
    Set myConnection = Nothing

    Dim myCDONTSMail
    Dim strFrom
    Dim strTo
    Dim strSubject
    Dim strBody

    strFrom=""
    strTo=Request.Form("EMail")
    strSubject = "Send to E-mail and Database"

    strBody ="The following information was submitted:" & Chr(13)
    strBody = strBody & Request.Form("FirstName") & " "
    strBody = strBody & Request.Form("LastName")
    strBody = strBody & Chr(13) & Request.Form("Address") & Chr(13)
    strBody = strBody & Request.Form("City") & Chr(13)
    strBody = strBody & Request.Form("Region") & Chr(13)
    strBody = strBody & Request.Form("PostalCode") & Chr(13)
    strBody = strBody & Chr(13) & "Thank you for submitting your data."

    Set myCDONTSMail = CreateObject("CDONTS.NewMail")
    myCDONTSMail.Send strFrom,strTo,strSubject,strBody
    Set myCDONTSMail = Nothing


    %>

    </head>

    <body bgcolor="#FFCC99">

    <p><font face="Verdana" color="#FF0000"><b>Thank you for submitting your
    information!<br>
    </b></font><font face="Verdana" size="2">You will receive an e-mail
    shortly. The e-mail was sent using the following information:</font></p>
    <b><b><font face="Verdana" size="2">Sent To: <br>

    <%
    Response.Write Request.Form("EMail")
    %>

    From: Microsoft PSS Sample Page</font></b></p>

    <p><b><font face="Verdana" size="2">Subject: Send to Database and
    E-mail</font></b></p>

    <p><b><font face="Verdana" size="2">Content:

    <%
    Response.Write(ParseBody(strBody))
    %>

    </font></b></p>
    <hr noshade size="1" style="color: #000000">
    <p> </p>

    </body>

    </html>
    ************************************************

    "Mike Brind" wrote:

    > If you think about the logic flow of your process, it should be fairly
    > obvious. You need the rep's email address before you can send an email
    > to him/her, right? So the email generation code has to go at some
    > point after the code that successfully retrieves this information from
    > your database.
    >
    > You have three actions to perform after you have retrieved the rep
    > info:
    > 1. Send an email
    > 2. Write to the db
    > 3. Display a confirmation page.
    >
    > I can't see that it matters in which order you code these actions.
    > None of them are dependent on the other, but all are dependent on
    > successful validation of the information submitted in the form.
    >
    > --
    > Mike Brind
    >
    > Ken D. wrote:
    > > Rob,
    > >
    > > Thanks for the reply. Not being a programmer, sometimes I am a bit
    > > challenged. Let me ask you this. I have an asp page that I built in
    > > Frontpage 2002 that upon submit, sends data to a SQL database and provides a
    > > confirmation to the user. I want to initiate the email to the rep selected
    > > in a combo box on the asp form at the same time the submit button is
    > > selected. I have a stored procedure that returns the last entered rep (and
    > > it works great). My question is, where do I insert your code in order to get
    > > it to fire at the submit event. I understand the script goes on my asp page
    > > but where does the strRepID and strEmailAddress go and how does it get called.
    > >
    > > Sorry to sound so confusing with this. Any help would be appreciated.
    > >
    > > Ken
    > >
    > > "Rob Meade" wrote:
    > >
    > > > "Ken D." wrote ...
    > > >
    > > > > Is it even possible to achieve what I am trying to do? I am trying to
    > > > > avoid
    > > > > sending a blanket email to a single address and having someone filter them
    > > > > from there.
    > > >
    > > > Hi Ken,
    > > >
    > > > If I'm following you correctly then yes...
    > > >
    > > >
    > > > In your code that handles the form being submitted...
    > > >
    > > > strRepID = request.form("repid") ' replace this with the name of your
    > > > drop down list - I'm assuming it contains an ID for the rep?
    > > >
    > > > ' run a query against your database to return the email address - a
    > > > stored procedure to return it based on the rep id might be nice
    > > > ' strEmailAddress = RS("RepsEmailAddress")
    > > >
    > > > ' send the email using the above string in the TO property
    > > > ' (see this article for an example on sending CDO emails
    > > > http://www.aspfaq.com/show.asp?id=2339)
    > > >
    > > > Hope this is of some help...you could tart it up a bit by doing some checks
    > > > to see if you returned a reps details or not and displaying a suitable
    > > > message if not, in addition your stored procedure could also get the reps
    > > > name and you could then on your confirmation page say "An email has been
    > > > sent to Mr A Rep" etc etc..
    > > >
    > > > Regards
    > > >
    > > > Rob
    > > >
    > > >
    > > >

    >
    >
     
    Ken D., Jun 14, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?c2FtZWVy?=
    Replies:
    1
    Views:
    925
    Bruce Barker
    Oct 4, 2005
  2. C.W.
    Replies:
    0
    Views:
    319
  3. Benoit Liard
    Replies:
    1
    Views:
    562
    Van Glass
    Jul 4, 2003
  4. Faisal Nasim
    Replies:
    0
    Views:
    302
    Faisal Nasim
    May 29, 2004
  5. Faisal Nasim
    Replies:
    0
    Views:
    353
    Faisal Nasim
    Sep 7, 2004
Loading...

Share This Page