...

View Full Version : Email Help



a_hook
01-19-2003, 09:20 PM
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

Morgoth
01-19-2003, 11:29 PM
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?

whammy
01-20-2003, 02:13 AM
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/ShowCategory.asp?CatID=10

That's where I originally learned CDONTS when I was new at ASP. :)

a_hook
01-20-2003, 09:35 PM
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

a_hook
01-20-2003, 09:38 PM
or post to a database via ODBC etc etc??


Regards
Anthony

whammy
01-20-2003, 11:59 PM
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

:)

whammy
01-21-2003, 12:39 AM
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:



<% @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.

a_hook
01-21-2003, 03:31 PM
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

Morgoth
01-21-2003, 09:41 PM
whammy always seems to come through like that.

whammy
01-22-2003, 04:17 PM
I forgot to mention I named it "addtolist.asp" and it posts to itself... but I guess you figured that out.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum