Join 3,370 readers in helping fund MetaFilter (Hide)


How do I collect email addresses?
February 18, 2008 6:54 AM   Subscribe

I need to code a form to gather contact information from visitors to my website, and I'm looking for alternatives to mySQL.

I need to make a form that collects name, address, phone number, and email address from visitors to a website. Our hosting company provides PHP, but as near as I can tell, they don't offer SQL. Unfortunately, the bosses really don't want to switch providers since the hosting company is owned by one of their friends.

Any suggestions on what I can do? I really don't want to just make the form send me an email. Can I have this thing output to a CSV, or an Access file or something? We're running some version of Apache on some sort of Unix (I can't be more specific because they have that stupid mod_security installed, and I don't have shell access).

Thanks!
posted by fvox13 to Computers & Internet (10 answers total) 5 users marked this as a favorite
 
For something that simple, just open a file with append and tack the details on the end.

Don't put the file in the webroot.

$fp = fopen('file.csv','a');
fprintf($fp, "%s, %s\r\n", $name, $email);
fclose($fp);
posted by Leon at 7:04 AM on February 18, 2008


Sure, you can have it write to a text file if you want, and then just turn it into CSV.
posted by gramcracker at 7:04 AM on February 18, 2008


(There's a real lack of error-checking in those 3 lines above, btw)
posted by Leon at 7:05 AM on February 18, 2008


Google Forms will dump the data into a spreadsheet for you.
posted by COD at 7:45 AM on February 18, 2008 [1 favorite]


I've been playing with Google apps - in the spreadsheet they recently implemented an ability to create web-based forms. You can just share the form, the data gets saved into the Google spreadsheet and then you can just play with in in OpenOffice or Excel. Fairly simple, a tiny bit buggy (make sure you enter all form layout information in the right order right from the start).

Sort-of works and requires absolutely nothing other than website and google docs.
posted by Yavsy at 7:46 AM on February 18, 2008


Leon's version has a couple bugs, which might or not might come back to bite you later. A better version is this:
$fp = fopen( 'file.csv', 'a' );flock( $fp, LOCK_EX );fputcsv( $fp, array( $name, $email, $etc ) );fclose( $fp );

posted by sbutler at 8:06 AM on February 18, 2008


Appending to a file will break if you don't use file locking.

Web browser x opens the file
x writes part
Web browser Y opens the file
y writes all
x finishes writing
x closes file
y closes file

Bang. Bad data.

My best advice, to make the simplest possible thing, is make a directory, and create files in it with the name of the email address. They're probably empty, the files, unless you want to store more info. That pushes locking on the file (the directory) into the kernel, so you needn't worry about it.

Make sure no email address contains a directory separator.

assert('/' not in $email);
$fp = fopen('emailaddresses/'+$email,'a');
fprintf($fp, "%s\r\n", $name);
fclose($fp);

$ ls email_addresses
fvox13@mefi.com
posted by cmiller at 8:10 AM on February 18, 2008


There are quite a few third-party services like Freedback.com or wufoo.com that can handle all the heavy lifting for you.
posted by bprater at 8:49 AM on February 18, 2008


The SQLite extension provides a Database that's handled completely by the client libraries, in this case by PHP, without the need for any server software. So if you could use that, it could do the trick, the docs are located at:

http://php.net/manual/en/ref.sqlite.php

Sounds like it might be exactly what you need.

Or, you could always pick up a hosting account that offers MySQL where you can have remote access, and just allow the website ips access over the internet - not ideal, but for lightweight stuff would also work. (I've done it once or twice short term when in a pinch)
posted by paulfreeman at 9:10 AM on February 18, 2008


You might try Tawala. They claim to make it easy to create web forms and collect data - their audience is non-programmers, so I imagine it would be dead-simple to create and email address collector. Disclaimer - I know one of the founders.
posted by zippy at 11:30 PM on February 18, 2008


« Older What do you call your signific...   |  Why does my dog lift one of hi... Newer »
This thread is closed to new comments.