[contrib] Method for Selecting Recipients by Zip Code

3rd party code for phpList

[contrib] Method for Selecting Recipients by Zip Code

Postby kyleknapp » 4:25pm, Fri 18 Apr, 2008

It is EXTREMELY important to me to be able to target mail recipients by zip code, and phplist just doesn't have any workable way to do this. So here is a solution. It's not elegant (maybe someone could improve on it?), but it does work.

It requires that you have attributes in your database as:

'Zip Code' (type: textline)
'Targeted' (type: checkbox)
(these can be named anything)

The files you need can be downloaded HERE

Files are:
targetzip.php (the script that does the job)
zipcodes.tab (sample list of zip codes to be targeted)
listattr.php (displays your attributeIDs)

In the attached targetzip.php script, you'll need to change your database login parameters, as well as the following 2 variables:

$zipcodeattr = "7"; //attributeid for zipcode field
$targetdattr = "16"; //attributeid for 'targeted' field


These must be replaced with the appropriate attributeid's from your database (CAUTION: if you get these wrong you could erase valuable data. Your attribute definitions are stored in table 'phplist_user_attribute'. You can view it using something like phpMyAdmin, or use the attached quick & dirty script 'listattr.php' to list your user-defined attributes)

Okay, here's how it works: the script 'targetzip.php'

-first clears all 'targeted' flags from any previous selection, then

-reads zipcodes from'zipcodes.tab' (the attached sample is a list of all zip codes within 100 miles of Wheaton IL)

-generates a list of userids matching each zipcode in the list, and

-sets the 'targeted' flag to 'on' for each user that matches

You can then use your 'targeted' attribute as a mailing criterion.

To determine what zip codes are selected, simply edit 'zipcodes.tab' using Excel or a text editor and re-upload. I use a program called 'Zip Code Distance Wizard' to find zipcodes within a specified radius of my target location.

Hope this helps someone. I'm a total newbie at PHP and mySQL, but I sure learned a lot doing this.

~kyle
kyleknapp
PL Geek
 
Posts: 67
Joined: 6:39pm, Tue 29 Aug, 2006
Location: Omaha, NE

Postby J_S » 7:51pm, Wed 23 Apr, 2008

This is great.
Thanks a lot!
J_S
Admin
 
Posts: 674
Joined: 10:18pm, Fri 11 Apr, 2003

Postby J_S » 8:02pm, Wed 23 Apr, 2008

It is already been posted as an issue on mantis :
http://mantis.phplist.com/view.php?id=8242
J_S
Admin
 
Posts: 674
Joined: 10:18pm, Fri 11 Apr, 2003

Re: [contrib] Method for Selecting Recipients by Zip Code

Postby NoahJenda » 8:39pm, Sun 09 Aug, 2009

I'm very new to phplist - I've only been running it a few days. Please pardon my newbie question.

I'd like to use this method for selecting recipients by zip code. I have followed the instructions as closely as possible. I correctly added the two required attributes and otherwise configured the options correctly in targetzip.php

I got it work exactly once. It read the sample zipcodes.tab file and produced the following output:

clearing `targeted` flags
flags cleared - proceeding

reading zipcode list from file
selecting userids for
6 userids selected
0 userid: 3
1 userid: 7
2 userid: 401
3 userid: 1928
4 userid: 1976
5 userid: 1990
finished with zipcode:

total of 6 records selected
done

I was able to successfully send email to this test group. Adding the criteria worked as expected. Everything seemed to working perfectly.

The problem is, I can't get it to run again. I've uploaded a new zipcodes.tab file (produced with Zip Code Distance Wizard) and I should see totally different results. However, when I click the link in the plugins menu, which I assumed would run the script again and read the new zipcodes file, it didn't work. I get exactly the same matches I got the first time I ran it.

It doesn't even seem to be reading the new data file. I suspect I only got it run once, and now it's just displaying the previous results. I even tried deleting the zipcodes.tab file, and it still produced the same result.

It may be a basic problem with my understanding of the installation of plugins. I couldn't get this to work without creating an extra file that lives in the /plugins directory and points to the targetzip.php file in a /plugins/zipcodes directory - perhaps this was a mistake.

What am I doing wrong? I'd really like to get this to work, so any help would be appreciated.

UPDATE:
Perhaps my problem is trying to use this method as a plugin.

When I run it from the command line, it seems to work fine.

Is this supposed to be run as a plugin or with a browser, or is the command line the only way it's supposed to work?

Again, my apologies for the newbie questions.
NoahJenda
phpLister
 
Posts: 6
Joined: 8:16pm, Sun 09 Aug, 2009

Re: [contrib] Method for Selecting Recipients by Zip Code

Postby kyleknapp » 9:52pm, Sun 09 Aug, 2009

The display you've described doesn't make sense - it should be displaying each zipcode in your input file, and each userid selected in that zipcode. It looks like your input file has no zipcodes in it, so the program accordingly targeted every user in your database with a blank zipcode. I think you'll get this result if your zipcodes.tab is deleted, or is in the wrong location so the program can't find it.

zipcodes.tab needs to be in the same folder as targetzip.php (unless you modify the code to look for it somewhere else.
kyleknapp
PL Geek
 
Posts: 67
Joined: 6:39pm, Tue 29 Aug, 2006
Location: Omaha, NE

Re: [contrib] Method for Selecting Recipients by Zip Code

Postby NoahJenda » 10:00pm, Sun 09 Aug, 2009

Thanks for the quick response!

I do have the targetzip.php and zipcodes.tab files in the same directory. Everything is working fine if I run it from the command line.

Was it ever meant to run from as a plugin? It's only when I try to run it via a web browser that I run into trouble. I'm probably trying to get it to do something it was never meant to do.

Do other users run targetzip.php from the command line, or is there another method?
NoahJenda
phpLister
 
Posts: 6
Joined: 8:16pm, Sun 09 Aug, 2009

Re: [contrib] Method for Selecting Recipients by Zip Code

Postby kyleknapp » 10:01pm, Sun 09 Aug, 2009

UPDATE:
Perhaps my problem is trying to use this method as a plugin.

When I run it from the command line, it seems to work fine.

Is this supposed to be run as a plugin or with a browser, or is the command line the only way it's supposed to work?

Again, my apologies for the newbie questions.


Ah, I see. Yes, from one newbie to another, I haven't been a programmer since the 80s, and have no clue at all how to create a plugin. I'm just an amateur who tinkered with basic PHP coding until I figured out how to make it do this - I'm sure it's a terribly clumsy and inefficient bit of code, but it seems to work for me. I've been hoping since I wrote this that someone smarter would find it important enough to re-code as a plugin, or incorporate into the next revision of PHPlist.

Anyway, the only way I know of for this to work is from the command line.
kyleknapp
PL Geek
 
Posts: 67
Joined: 6:39pm, Tue 29 Aug, 2006
Location: Omaha, NE

Re: [contrib] Method for Selecting Recipients by Zip Code

Postby kyleknapp » 10:02pm, Sun 09 Aug, 2009

Do other users run targetzip.php from the command line, or is there another method?


I'm not aware that anybody uses this but me...
kyleknapp
PL Geek
 
Posts: 67
Joined: 6:39pm, Tue 29 Aug, 2006
Location: Omaha, NE

Re: [contrib] Method for Selecting Recipients by Zip Code

Postby NoahJenda » 10:10pm, Sun 09 Aug, 2009

I'm not aware that anybody uses this but me...


There's two of us now, at the very least.

I'm using it to send targeted messages for a touring Blues musician, so he can email fans on his list when he's playing within a certain radius of their zip codes.
NoahJenda
phpLister
 
Posts: 6
Joined: 8:16pm, Sun 09 Aug, 2009

Re: [contrib] Method for Selecting Recipients by Zip Code

Postby NBC » 9:46am, Mon 04 Oct, 2010

Where I have to upload the files? I tried uploaded this files in root but I can´t search in phplist. If I used browser it works but how I can write mails now?
NBC
phpList newbie
 
Posts: 4
Joined: 9:42am, Mon 04 Oct, 2010


Return to Contributions: Plug-ins, Add-ons, Mods

Who is online

Users browsing this forum: No registered users and 2 guests