Title: programmatically adding subscribers
Last modified: August 21, 2016

---

# programmatically adding subscribers

 *  Resolved [batman42ca](https://wordpress.org/support/users/batman42ca/)
 * (@batman42ca)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/programmatically-adding-subscribers/)
 * I have a custom registration form that permits the user to register for various
   programs. Each program has it’s own mailing list so based on the selected program,
   I want my code to add the user to the appropriate mailing list.
 * It looks like I need to call:
 * alo_em_add_subscriber_to_list ( $subscriber->ID, $list_id );
 * $list_id. I understand, but since the user will not be logged into WordPress,
   what do I use for $subscriber->ID?
 * The other way, I guess, is to directly add a record to the “wp_easymail_subscribers”
   database table. For the “unikey” field, can I just use UUID() from Mysql?
 * [http://wordpress.org/extend/plugins/alo-easymail/](http://wordpress.org/extend/plugins/alo-easymail/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [eventualo](https://wordpress.org/support/users/eventualo/)
 * (@eventualo)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/programmatically-adding-subscribers/#post-3850263)
 * Here you are the right sequence:
 *     ```
       $fields['email'] = $email; // from your custom form
       $fields['name'] = $name; // from your custom form
       $lang = ''; // language, optional: 2 letters code, e.g. "en"
       if ( alo_em_add_subscriber( $fields, 1, $lang ) == "OK" )
       {
           $subscriber_id = alo_em_is_subscriber ( $email );
           alo_em_add_subscriber_to_list ( $subscriber_id, $list_id );
       }
       ```
   
 * Otherwise, of course, insert directly in database table. About “unikey”, you 
   should create a random alphanumeric string (the plugin checks allow only letters
   and numbers). In php I’m using:
 *     ```
       $unikey = substr(md5(uniqid(rand(), true)), 0,24);
       ```
   
 *  Thread Starter [batman42ca](https://wordpress.org/support/users/batman42ca/)
 * (@batman42ca)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/programmatically-adding-subscribers/#post-3850303)
 * Thanks for the response. That’s very helpful.
 * One further question. Only knowing the name of the mailing list, where can I 
   look up the id of the list? The list ids will be dependent on the order in which
   they were added to WordPress. I’d rather not hard code those numbers. I like 
   to use the name of the mailing list instead.
 * I’ve poked around the WordPress database tables but I haven’t found where that
   information is stored yet.
 *  Thread Starter [batman42ca](https://wordpress.org/support/users/batman42ca/)
 * (@batman42ca)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/programmatically-adding-subscribers/#post-3850318)
 * I should clarify. I know where to see the mailing list id’s for myself. What 
   I mean is, someone selects a program from my form and the name of the program
   is also the name of the mailing list. I could create my own look up table of 
   hard coded numbers to translate a program name to a mailing list id, but I’d 
   rather be able to use a mailing list name to look up the mailing list id in the
   database.
 * Should I call alo_em_get_mailinglists() and loop through the returned array looking
   for an entry matching the mailing list name and get the mailing list id from 
   that?
 *  Thread Starter [batman42ca](https://wordpress.org/support/users/batman42ca/)
 * (@batman42ca)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/programmatically-adding-subscribers/#post-3850363)
 * For anyone reading this, I can confirm that the above code and my plan to use
   alo_em_get_mailinglists() works.
 * Problems solved.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘programmatically adding subscribers’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/alo-easymail_574f4b.svg)
 * [ALO EasyMail Newsletter](https://wordpress.org/plugins/alo-easymail/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/alo-easymail/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/alo-easymail/)
 * [Active Topics](https://wordpress.org/support/plugin/alo-easymail/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/alo-easymail/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/alo-easymail/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [batman42ca](https://wordpress.org/support/users/batman42ca/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/programmatically-adding-subscribers/#post-3850363)
 * Status: resolved