Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: Email Help

  1. #1
    New to the CF scene
    Join Date
    Jan 2003
    Location
    Tonbridge
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Email Help

    I wish to create asimple script that enables a user of my site to enter there email address into a form (text field)

    and then the email address is either added to a text file or sent to my email address???

    WITHOUT having to send it via the users email client

    Help would be appreciated

    Regards
    Anthony

  • #2
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    You need something for this then.

    You need to have a host with an SMTP server. Either hat host is yourself, or something you are most likley paying for.

    If you do not know what an SMTP server is then this is going to be even more tricky.

    What host do you use? Your own computer?

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Great, that's what ASP is for... first of all I would check out some ASP tutorials (a google search should turn up plenty, and there have been a plethora of posts about "good asp hosts" and "asp tutorials" posted right here in the forum if you do a search).

    For email scripts specifically, check out this link:

    http://www.aspfaqs.com/aspfaqs/ShowC...y.asp?CatID=10

    That's where I originally learned CDONTS when I was new at ASP.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #4
    New to the CF scene
    Join Date
    Jan 2003
    Location
    Tonbridge
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah i have a 2 accounts that have total full support (cost like 50 squid a month like....i dont pay for them!!)

    but yeah they have smtp servers etc i am looking for a script preferably asp...cause i know a little asp and i am able to easily edit them etc

    hope somebody can post me this exact script or somehthing similar:

    ---------------------
    i am after
    ---------------------

    a script that user of a site can enter an email addrss into a simple form....click submit and it then writes the email address to a text file in my host directory.....i dont want it to auto matically send it out....i have one that does this.....


    Regards
    Anthony

  • #5
    New to the CF scene
    Join Date
    Jan 2003
    Location
    Tonbridge
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    or post to a database via ODBC etc etc??


    Regards
    Anthony

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    For the first, easily done with FileSystemObject:

    http://www.w3schools.com/asp/asp_ref_filesystem.asp

    You might want to look at a simple email form (this sends OUT the email) as an example of posting to the same page:

    http://www.solidscripts.com/email.txt

    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's a very quick working example of appending an email address to a text file using a form, this even checks to make sure it doesn't already exist:

    Code:
    
    <% @Language="VBScript" %>
    <% Option Explicit %>
    <%
    '*************************************** FUNCTIONS
    
    Function IsEmail(str)
       Dim ieRegEx
       Set ieRegEx = New RegExp
       ieRegEx.Pattern = "^[\w\+\'\.-]+@[\w\'\.-]+\.[a-zA-Z0-9]{2,}$"
       IsEmail = ieRegEx.Test(str)
    End Function
    
    '*********************************** DIM VARIABLES
    
    Dim Email, SubmitNum ' Requested variables
    Dim Found            ' Variable to check for duplicate emails
    Dim fs, f, filepath  ' FileSystemObject variables
    
    '******************** REQUEST/INITIALIZE VARIABLES
    
    Email = Request.Form("Email")
    SubmitNum = Request.Form("SubmitNum")
    filepath = Mid(Server.MapPath("\"), 1, InStrRev(Server.MapPath("\"),"\")-1) & "\database\emaillist.txt"
    
    '************************************ MAIN PROGRAM
    
    SubmitNum = SubmitNum + 1
    
    If IsEmail(Email) Then
       Call LookupEmail()
       If Found = False Then
          Call AppendEmail()
          Call DisplayThankYou()
       Else
          Call DisplayDupeMessage()
       End If
    Else
       Call DisplayForm()
    End If
    
    '******************************** END MAIN PROGRAM
    
    '************************************* SUBROUTINES
    
    Sub LookupEmail()
       Found = False
       Set fs = CreateObject("Scripting.FileSystemObject")
       Set f = fs.OpenTextFile(filepath,1,True)
       Do While NOT f.AtEndOfStream AND Found = False
          If f.ReadLine = Email Then Found = True
       Loop
       Set f = Nothing
       Set fs = Nothing
    End Sub
    
    Sub AppendEmail()
       Set fs = CreateObject("Scripting.FileSystemObject")
       Set f = fs.OpenTextFile(filepath,8,True)
       f.WriteLine(Email)
       Set f = Nothing
       Set fs = Nothing
    End Sub
    %>
    
    
    <% Sub DisplayThankYou() %>
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
       "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
    <head>
       <meta http-equiv="refresh" content="3;URL=addtolist.asp" />
       <title>Thank You!</title>
    </head>
    <body>
       <div><span style="font-weight:bold">Thank you for subscribing!</span></div>
    </body>
    </html>
    <% End Sub %>
    
    
    <% Sub DisplayDupeMessage() %>
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
       "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
    <head>
       <meta http-equiv="refresh" content="3;URL=addtolist.asp" />
       <title>Your email address already exists!</title>
    </head>
    <body>
       <div><span style="font-weight:bold">Your email address already exists in our database!</span></div>
    </body>
    </html>
    <% End Sub %>
    
    
    <% Sub DisplayForm() %>
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
       "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
    <head>
       <title>Please enter your email address to subscribe!</title>
    </head>
    <body>
       <form id="addtoemaillist" method="post" action="addtolist.asp">
          <input type="text" name="Email" value="<% = Email %>" />
          <% If SubmitNum > 1 Then %>
          <span style="color:#ff0000"> * Invalid Email Address</span>
          <% End If %>
          <br />
          <input type="hidden" name="SubmitNum" value="<% = SubmitNum %>" />
          <input type="submit" value="Submit" />
       </form>
    </body>
    </html>
    <% End Sub %>
    
    Some people here say I have an "interesting" coding style (but if I'm not mistaken, it is very understandable, and it works). It probably comes from learning BASIC when I was a kid (lots of SUBs and DATA statements in that language!), and not touching a computer for another 15 years...



    P.S. Pay special attention to this part:

    filepath = Mid(Server.MapPath("\"), 1, InStrRev(Server.MapPath("\"),"\")-1) & "\database\emaillist.txt"

    That's all done to access the text file (or, for instance, an access database) which should be stored in a folder ABOVE your root folder (i.e. "database"), so it cannot be downloaded by unscrupulous individuals simply typing in the domain/filename in their address bar if they happen to guess it.

    You will see this exact same practice used on just about any host that provides Access databases to store data, such as brinskter.com.

    Not the utmost in security, but a *must* if you're using an Access database or a text file to store information.
    Last edited by whammy; 01-21-2003 at 01:22 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #8
    New to the CF scene
    Join Date
    Jan 2003
    Location
    Tonbridge
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wow thank you very much i have tested the script on my pc and it works great will let you know when i have it online....


    Regards
    Anthony

  • #9
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    whammy always seems to come through like that.

  • #10
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I forgot to mention I named it "addtolist.asp" and it posts to itself... but I guess you figured that out.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

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