SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    South-West UK
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Send mail question

    Hello all,

    I've got this script (below) which adds info to a database after a form submission, but I would like to add a mailing script to this which e-mails the person to send them thier username and password etc. so they can keep it safe.

    I'm not too sure where I should add the mailing code though,....wondered if anyone could point me in the right direction.

    Here's the code which adds the infor to the database:

    [VBS]<% @LANGUAGE = VBSCRIPT %>
    <%
    If request("action") = "register" Then
    username=trim(request("username"))
    %>
    <!--#include file="inc-dbconnection.asp"-->
    <%
    set Rs=server.Createobject("ADODB.RECORDSET")
    sql="SELECT * FROM members WHERE username='"&username&"'"
    Rs.Open sql,objConn,1,3
    If rs.eof Then
    rs.AddNew
    rs("username") = username
    rs("password") = request("password")
    rs("sex") = request("sex")
    rs("Fname") = trim(request("Fname"))
    rs("Lname") = trim(request("Lname"))
    rs("Email") = trim(request("Email"))
    rs("organization") = request("organization")
    rs("location") = request("location")
    rs("info") = request("info")
    rs("info2") = request("info2")
    If request("expertise_general") <> "" Then rs("expertise_general") = 1
    If request("expertise_people_management") <> "" Then rs("expertise_people_management") = 1
    If request("expertise_work_in_partnership") <> "" Then rs("expertise_work_in_partnership") = 1
    If request("expertise_project_management") <> "" Then rs("expertise_project_management") = 1
    If request("expertise_service_development") <> "" Then rs("expertise_service_development") = 1
    If request("expertise_equality") <> "" Then rs("expertise_equality") = 1
    If request("expertise_user_involvement") <> "" Then rs("expertise_user_involvement") = 1
    If request("shadow") <> "" Then rs("shadow") = 1




    rs.Update
    rs.close
    set rs = nothing
    objConn.close
    set objConn = nothing
    response.Redirect "thankyou_1.asp"
    Else
    response.Redirect "sorry_password.asp"
    End If
    Else
    %>
    <html> blah de blah </html>
    <%
    End If
    %>[/VBS]
    I've got this bit of code below (which I know will need a few modifications, but don't know where would be a good place to add it:

    [VBS]<%
    Set Mail = CreateObject("CDONTS.Newmail")
    If request("email")="" then
    Sender = "me@home.com"
    Else
    Sender = request("email")
    End If
    Mail.From = Sender
    Mail.To = "me@home.com"
    Mail.Subject = "Thankyou for registering"
    Msg = "First Name: " & request("Fame") & Chr(10)
    Msg = Msg & "Last Name: " & request("Lname") & Chr(10)
    Msg = Msg & "Your username: " & request("username") & Chr(10)
    Msg = Msg & "Your password: " & request("password") & Chr(10)
    Mail.Body = Msg
    Mail.Send
    Set Mail = Nothing
    %>[/VBS]

    Any help pointing out where I could add it to the first script would be greatly appreciated.

    Thanks
    Matt

  2. #2
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That example script you have is for controlling MS SMTP mail services. You need to know what sort of mail s/w your host supports. Some use JMail, others use ASPMail, and .NET mail is becoming popular now too. Which s/w is on your server will affect the script you need.

    G

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    South-West UK
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My host supports CDONTS mail.

  4. #4
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. Just making sure you'd checked that out.

    I'd personally keep the mail script separate (I've marked in bold my changes):

    Code:
    <% @LANGUAGE = VBSCRIPT %>
    <%
    If request("action") = "register" Then
    username=trim(request("username"))
    
    strPassword = request("password")
    strEmail = Trim(request("Email"))
    
    %> 
    <!--#include file="inc-dbconnection.asp"-->
    <%
    Set Rs=server.CreateObject("ADODB.RECORDSET")
    sql="SELECT * FROM members WHERE username='"&username&"'"
    Rs.Open sql,objConn,1,3
    If rs.EOF Then
    rs.AddNew
    rs("username") = username
    rs("password") = strPassword
    rs("sex") = request("sex")
    rs("Fname") = Trim(request("Fname"))
    rs("Lname") = Trim(request("Lname"))
    rs("Email") = strEmail
    rs("organization") = request("organization")
    rs("location") = request("location")
    rs("info") = request("info")
    rs("info2") = request("info2")
    If request("expertise_general") <> "" Then rs("expertise_general") = 1
    If request("expertise_people_management") <> "" Then rs("expertise_people_management") = 1
    If request("expertise_work_in_partnership") <> "" Then rs("expertise_work_in_partnership") = 1
    If request("expertise_project_management") <> "" Then rs("expertise_project_management") = 1
    If request("expertise_service_development") <> "" Then rs("expertise_service_development") = 1
    If request("expertise_equality") <> "" Then rs("expertise_equality") = 1
    If request("expertise_user_involvement") <> "" Then rs("expertise_user_involvement") = 1
    If request("shadow") <> "" Then rs("shadow") = 1
    
    
    rs.Update
    rs.Close
    Set rs = nothing
    objConn.Close
    Set objConn = nothing
    
    
    '### send your mail here
    
    Set Mail = CreateObject("CDONTS.Newmail")
    Sender = "me@home.com" 
    Mail.From = "your.email@your.host, Your Name"
    Mail.To = strEmail
    
    Mail.Subject = "Thankyou For registering"
    
    Msg = "Username: " & username & Chr(10)
    Msg = Msg & "Password " & strPassword & Chr(10)
    Msg = Msg & "Don't lose it!!"
    
    Mail.Body = Msg
    Mail.Send
    Set Mail = Nothing
    
    response.Redirect "thankyou_1.asp"
    Else
    response.Redirect "sorry_password.asp"
    End If
    Else
    %> 
    <html> blah de blah </html>
    <%
    End If
    %>

  5. #5
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the way. You use SQL to check for an existing username so why don't you use SQL to insert a new row? It's a much tidier way of connecting to your database. And faster. Go to http://www.w3schools.com/sql/default.asp and read up on UPDATE and INSERT queries -- it's very good.

    Also, this:
    Code:
    Set Rs=server.CreateObject("ADODB.RECORDSET")
    sql="SELECT * FROM members WHERE username='"&username&"'"
    Rs.Open sql,objConn,1,3
    ... can simply be this:
    Code:
    sql="SELECT * FROM members WHERE username='"&username&"'"
    Set rs = objConn.Execute(sql)
    G

  6. #6
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    South-West UK
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Greg,

    Thanks for all that,.... I'l give it all a go and let you know how it all works...

    Cheers mate.

    Matt


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •