New Subscriber Notifications
-
Hi there,
Is there a way to make MailPoet 3 send emails to a specified address when a new subscriber is successfully subscribed?
Is there some way to hook into MailPoet to accomplish this or some hidden option somewhere?
Thanks!
-
I’m facing the same problem, searching for a way to get a notification when someone subscribes to a list.
Erwin
Yes…why is this feature not supported in MailPoet 3…in MailPoet II it was possible
Hey,
That feature is currently not present on MailPoet 3.
However, it might be in the future. ??
oh…this is reason to use MailPoet 2 instead of 3
oh…this is reason to use MailPoet 2 instead of 3
Except that MailPoet 2 is likely going to stop getting updates eventually and therefore likely get pulled from www.remarpro.com at some point.
If you aren’t going to add this feature or even if you are, could you please describe a way to intercept the form submission data so that I might be able to use the wp_mail function to send that data to someone?
I’ve tried hooking into the admin_post_nopriv_mailpoet_subscription_form and admin_post_mailpoet_subscription_form actions as well as the wp_redirect filter to no avail. I’m not sure why but I can’t get any of the form data at any point in the request no matter where I try to do it, even if it’s right in the root file of a plugin or in the functions.php of the theme, there is no POST, GET or REQUEST data from that form going through due to the request going to the admin-post file and somehow that is not giving me anything in the hooks I’ve tried which I’m not understanding.
The only thing I found I can do is add a shortcode that goes into the “After submit… Go to page” and use the MailPoet Export getSubscribers function to get all the subscribers and loop through them keeping a transient cache of the ones I’ve sent notifications for. However this isn’t ideal nor will it work in this case because the form can be submitted multiple times on this site I’m working on and has to send a notification each time with the submitted data.
Any ideas? Please add more hooks everywhere.
I agree completely to @rrhode…
I migrated from 2 to 3, the GET new feature, not to loose some…
If I knew this woud be impossible, I kept on using version 2…Can you please let us know if there are plans to implement it again? I STRONGLY recommend that.
Erwin
I had to have this so I wrote a way to do it but it may not be ideal for everyone and isn’t necessarily quite finished yet so I can’t include any code for it. I’m sure they will add this feature eventually in a nicer way.
I actually made two ways to do it, the first way I no longer have or am using but it would attempted to detect the URL parameters in the confirmation link and then get the subscriber data from the users by using the MailPoet Export->getSubscribers function and keep a transient cache of subscribers that the admin have already been sent a notification for. Then it would simply use the wp_mail function to send an email.
However for the client this was no good because they required some forms to be submitted multiple times, as well as subscribe them to multiple lists. So in the end I created a shortcode to add into the content of the page indicated in the “After submit… Go to page” setting in the form settings. The shortcode has an email parameter to send the notifications to. I made it send the notifications by querying the database directly for subscribers who have the updated_at field modified within the last 10 seconds which should get the last subscriber who just submitted the form. I then take the unconfirmed_data field and parse the JSON out and get the custom fields data from here. I couldn’t find it anywhere else but glad it’s here. It’s only there until they click the confirm link though. It’s quite hacky but it actually works. The only issue might be if multiple people are submitting the form at the same time within 10 seconds it may cause duplicate notifications but I guess that’s fine and quite likely won’t happen anyway in this case.
Anyway, maybe that will help someone.
Works for me. Wp4.8.3.
I would like this feature too.
@rrhode is there any way you can share your code that others can use as a starting point? I just learned about this problem today and I need to come up with a solution quickly. Thanks for your help.
Sure, let’s see if I can get it to work properly. Although you will have to modify it to match your form fields. There are a number of custom fields added in here for their particular form and I didn’t bother adding those dynamically yet. I’m not sure if that’s even possible but I wanted the email formatted a specific way too.
Anyway, this adds a shortcode to add into the content of the page indicated in the “After submit… Go to page” setting in the form settings. The shortcode has a “to” parameter for an email address to send the notifications to and defaults to the admin email in the WP settings.
Example usage:
[send-mp-notification to="[email protected]"]
In my case I created a new plugin to put this code into. So you should just have to make a new file at wp-content/plugins/mpnotifications.php and put this code into it after adjusting the fields accordingly.
<?php /* Plugin Name: MP Notifications Plugin URI: https://servercode.ca/ Description: Provides notifications for MailPoet form submissions. Author: Ryan Rhode Version: 1.0 Author URI: https://servercode.ca/ */ // TODO: dynamic custom fields if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Shortcode to send notifications to admins on new subscribers. * * Note: Field names are cf_# where # is the id column in wp_mailpoet_custom_fields * * @param $atts */ function custom_notify_of_new_subscribers( $atts ) { global $wpdb; $a = shortcode_atts( array( 'to' => get_bloginfo( 'admin_email' ) ), $atts ); $subscribers = $wpdb->get_results( 'SELECT * FROM <code>wp_mailpoet_subscribers</code> WHERE <code>updated_at</code> > NOW() - INTERVAL 10 SECOND', ARRAY_A ); foreach ( $subscribers as $subscriber ) { $data = array(); if ( isset( $subscriber['unconfirmed_data'] ) && ! empty( $subscriber['unconfirmed_data'] ) ) { // updated existing subscriber // {"email":"[email protected]","first_name":"John","last_name":"Smith","cf_1":"12345","cf_2":"123-123-1234","cf_7":"1","cf_4":"Some additional comments"} $data = json_decode( $subscriber['unconfirmed_data'], true ); } else { // new subscriber $data['first_name'] = $subscriber['first_name']; $data['last_name'] = $subscriber['last_name']; $data['email'] = $subscriber['email']; $fields = $wpdb->get_results( 'SELECT custom_field_id,value FROM <code>wp_mailpoet_subscriber_custom_field</code> WHERE <code>subscriber_id</code>=' . intval( $subscriber['id'] ), ARRAY_A ); foreach ( $fields as $field ) { if ( $field['custom_field_id'] == 1 ) { // zip $data['cf_1'] = $field['value']; } if ( $field['custom_field_id'] == 2 ) { // phone $data['cf_2'] = $field['value']; } if ( $field['custom_field_id'] == 4 ) { // additional comments $data['cf_4'] = $field['value']; } if ( $field['custom_field_id'] == 6 ) { // windows $data['cf_6'] = $field['value']; } if ( $field['custom_field_id'] == 7 ) { // doors $data['cf_7'] = $field['value']; } if ( $field['custom_field_id'] == 8 ) { // siding $data['cf_8'] = $field['value']; } if ( $field['custom_field_id'] == 9 ) { // gutters $data['cf_9'] = $field['value']; } if ( $field['custom_field_id'] == 10 ) { // roofs $data['cf_10'] = $field['value']; } } } $subject = "New form submission on " . sanitize_text_field( html_entity_decode( get_bloginfo( 'name' ) ) ); $message = ""; $message .= "First Name: " . sanitize_text_field( $data['first_name'] ) . "\r\n"; $message .= "Last Name: " . sanitize_text_field( $data['last_name'] ) . "\r\n"; $message .= "Email: " . sanitize_email( $data['email'] ) . "\r\n"; if ( isset( $data['cf_1'] ) ) { $message .= "Zip: " . sanitize_text_field( $data['cf_1'] ) . "\r\n"; } if ( isset( $data['cf_2'] ) ) { $message .= "Phone: " . sanitize_text_field( $data['cf_2'] ) . "\r\n"; } $interests = array(); if ( isset( $data['cf_6'] ) && $data['cf_6'] == 1 ) { $interests[] = "Windows"; } if ( isset( $data['cf_7'] ) && $data['cf_7'] == 1 ) { $interests[] = "Doors"; } if ( isset( $data['cf_8'] ) && $data['cf_8'] == 1 ) { $interests[] = "Siding"; } if ( isset( $data['cf_9'] ) && $data['cf_9'] == 1 ) { $interests[] = "Gutters"; } if ( isset( $data['cf_10'] ) && $data['cf_10'] == 1 ) { $interests[] = "Roofs"; } if ( ! empty( $interests ) ) { $message .= "Interests: " . implode( ',', $interests ) . "\r\n"; } if ( isset( $data['cf_4'] ) ) { $message .= "Additional Comments: " . sanitize_text_field( $data['cf_4'] ) . "\r\n"; } wp_mail( sanitize_email( $a['to'] ), $subject, $message ); } } add_shortcode( 'send-mp-notification', 'custom_notify_of_new_subscribers' );
- This reply was modified 6 years, 10 months ago by ryvix.
Thanks @rrhode for your quick reply. I had a new idea that I will also test where
1. I set up a cron job to query the mailpoet db for new subscribers.
2. I loop through new subscriber list from query
3. I use the Mailpoet getSubscribers function to get the rest of the subscriber details.
4. I email or do whatever I want such as post data to Zapier or another system.If I make it work, I will share it with you. However, I will probably use your solution first as it should be quicker at the moment.
Yeah I thought about doing a cron as well but ended up doing it this way instead.
I think WP messes with the formatting so here it is as a gist: https://gist.github.com/ty2u/36fbc912d7dd886e5057ba6911cd794f
Same feature request here, so: following…
And what??
5 months later, nothing new. Still no email notification after registration ?
What are doing the dev of MailPoet ? Seriously!
Regard.
- This reply was modified 6 years, 6 months ago by spoonconcept.
- The topic ‘New Subscriber Notifications’ is closed to new replies.