Getting Persits AspEmail to work from scratch

Discussion in 'Classic ASP' started by raymondp, Nov 12, 2007.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Fellow Developers

    As an aspiring programmer I am taking a little too long in finding out how to put this Email Program to work. I have installed it and read the manual but it still seems a little advanced for my level. I would like some of you to please explain me from scratch how to do this. Sort of for 'Dummies' style, if possible. I have, however, built a form which stores the users' data into a DB and I'd like to automatically send them an email as they click the submit button to confirm that their 'bookings' have been successfully submitted (this is a online table booking system for a restaurant). I am running booking.asp (where the form is) and newbooking.asp (which is called by the action on booking.asp).

    Thanks in advance for any guidance on this issue.

    Rod.
     
  2. Fellow Programmers


    Ok the following code corresponds to the page called 'booking.asp' ,as you can see it is the form where customer books their table and it stores the values in a MS Access DB.


    <form name="bookingform" action="newbooking.asp" method="post" >
    <tr><td width="130">Email address</td>
    <td width="150"><input type="text" size=25 name="email"></td>
    <td width="230"></td>
    </tr>
    <tr>
    <td width="130">Home Phone</td>
    <td width="150"><input name="phone" type="text" id="phone" size="25" maxlength="10" /></td>
    <td><span class="style2">Do NOT include 2-digit prefix if NSW </span></td>
    </tr>
    <tr>
    <td width="130">Mobile (optional) </td>
    <td width="150"><input name="phone" type="text" id="mobile" size="25" maxlength="10" /></td>
    <td>&amp;nbsp;</td>
    </tr>
    <tr>
    <%
    Response.Write "<tr valign='center'>"
    Response.Write "<td>Date <font size='-1'> (dd-mm-yyyy)</font></td>"
    Response.Write "<td width='50'><input type='text' name='dDay' size='12'></input>"
    Response.Write "<input type=""button"" value=""Calendar"" onclick=""openChild('datepicker.asp','win2')""></input></td>"
    Response.Write "</tr><tr valign='center'>"
    Response.Write "</tr>"
    %>
    </tr>

    <tr><td width="200">First Name</td>
    <td width="150"><input name="fname" type="text" size="25" /></td>
    <td>&amp;nbsp;</td>
    </tr>
    <tr>
    <td width="200">Last Name</td>
    <td width="150"><input name="lname" type="text" size="25" /></td>
    <td>&amp;nbsp;</td>
    </tr>
    <tr>
    <td width="200">Time</td>
    <td width="150">
    <select name="tTime" id="tTime">
    <option>5:30</option>
    <option>6:00</option>
    <option>6:30</option>
    <option>7:00</option>
    <option>7:30</option>
    <option>8:00</option>
    <option>8:30</option>
    </select>PM </td>
    <td>&amp;nbsp;</td>
    </tr>
    <tr>
    <td width="200">Party of</td>
    <td width="150">
    <select name="persons" id="persons">
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    </select></td>
    <td>&amp;nbsp;</td>
    </tr>

    <tr>
    <td width="200" height="70"><input name="submit" type="submit" id="submit" value="Send" /></td>
    </tr>
    </form>
    And the following corresponds to the page called 'newbooking.asp' which is called by the action on the previous page. There's much more html and some js but it is not relevant (i guess) for this issue.
    As I mentioned before, everything is working well, so my question isWHERE do I put WHAT code to create the automated email sending feature? DO I use that sample code from Persits and insert it here somewhere? Thanks in advance.

    <%
    Dim strconn
    strconn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&amp;Server.MapPath("bookings.mdb")&amp;";"
    Dim ID, fname, lname, email, persons, dDay, tTime, phone, mobile

    ID=request.Form("ID")
    fname=request.Form("fname")
    lname=request.Form("lname")
    email=request.Form("email")
    persons=request.Form("persons")
    dDay=request.Form("dDay")
    tTime=request.Form("tTime")
    phone=request.Form("phone")
    mobile=request.Form("mobile")

    dim oCon
    set oCon = server.createobject("adodb.connection")
    oCon.open strconn

    dim strSql
    strSql = "INSERT INTO customers (First_Name, Last_Name, Email, Number_of_People, [Date], [Time], phone, mobile) VALUES ('"&amp;fname&amp; "','" &amp;lname&amp; "','" &amp;email&amp; "','" &amp;persons&amp; "','" &amp;dDay&amp; "','" &amp;tTime&amp; "','"&amp;phone&amp;"','"&amp;mobile&amp;"')"

    oCon.Execute strSql
    %>
    <head>
    </head>


    <%
    'rs.MoveNext
    'Loop
    %>
    <% 'rs.close()

    set oCon = Nothing
    end if
    %>

    Thanks a million.
     
  3. You can add the email code to your newbooking.asp as follows:

    <%
    Dim strconn
    strconn='DRIVER={Microsoft Access Driver (*.mdb)};DBQ='&Server.MapPath('bookings.mdb')&';'
    Dim ID, fname, lname, email, persons, dDay, tTime, phone, mobile

    ID=request.Form('ID')
    fname=request.Form('fname')
    lname=request.Form('lname')
    email=request.Form('email')
    persons=request.Form('persons')
    dDay=request.Form('dDay')
    tTime=request.Form('tTime')
    phone=request.Form('phone')
    mobile=request.Form('mobile')

    dim oCon
    set oCon = server.createobject('adodb.connection')
    oCon.open strconn

    dim strSql
    strSql = 'INSERT INTO customers (First_Name, Last_Name, Email, Number_of_People, [Date], [Time], phone, mobile) VALUES (''&fname& '','' &lname& '','' &email& '','' &persons& '','' &dDay& '','' &tTime& '',''&phone&'',''&mobile&'')'

    oCon.Execute strSql

    set objMessage = createobject('cdo.message')
    set objConfig = createobject('cdo.configuration')

    Dim ToAddress
    ToAddress= '[email protected]'

    if(Request.Form('email') <>'' and Request.Form('lname') <> '' and Request.Form('fname') <>'') Then

    ToAddress=request.Form('email')
    ' Setting the SMTP Server
    Set Flds = objConfig.Fields
    Flds.Item('http://schemas.microsoft.com/cdo/configuration/sendusing') = 2
    Flds.Item('http://schemas.microsoft.com/cdo/configuration/smtpserver') = 'localhost'
    Flds.update


    Set objMessage.Configuration = objConfig
    objMessage.To = ToAddress
    objMessage.From = '[email protected]'
    objMessage.Subject = 'Dear' + Request.Form('lname') +' '+ Request.Form('fname')
    objMessage.TextBody = 'Congratulations' & VbCrLf & 'If you receive this is, your mail component works'
    objMessage.fields.update
    objMessage.Send

    Response.write 'Mail sent...'

    set objMessage = nothing
    set objConfig = nothing
    Else

    'Do Something....

    End If
    %>

    This is just a sample.You may change the information as per your needs.

    Vikram

    DiscountASP.NET
    www.DiscountASP.NET
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page