• Resolved magaworks

    (@magaworks)


    Hi,
    I have some forms in landing pages redirecting the user to a new page after submit.
    I need to implement a function to fire an email do site admin to let the client know someone filled that form even if it is a user already subscribed.
    Is there a way to do this?
    A function I can call upon submission to send an email to someone after successful submission?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter magaworks

    (@magaworks)

    I see you have a filter:
    yikes-mailchimp-after-submission and yikes-mailchimp-after-submission-{$form_id} – Catch the merge variables after they get sent over to MailChimp. @params: $merge_variables
    I call call this filter to have the email sent, right? But what code should I write to send an email to a specific email from the wordpress? I am not a code expert so if you could help I would be really glad πŸ™‚
    Thanks.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @magaworks,

    This is a simple example of how to use the yikes-mailchimp-form-submission hook. It will fire any time a successful submission is captured.

    add_action( 'yikes-mailchimp-form-submission', 'yikes_send_email_after_submission', 10, 4 );
    
     function yikes_send_email_after_submission( $email, $merge_variables, $form_id, $notifications ) {
    
     	$content     = '<p>A user with the email ' . $email . ' has attempted to subscribe to your MailChimp list.</p>';
     	$content    .= '<p>Here is their information: </p><br>'; 
     	$content    .= print_r( $merge_variables, true );
     	$admin_email = '[email protected]';
     	$subject     = 'New MailChimp Submission.';
     	$headers     = array( 'Content-Type: text/html; charset=UTF-8' );
    
     	wp_mail( $admin_email, $subject, $content, $headers );
     }

    Cheers,
    Kevin.

    Thread Starter magaworks

    (@magaworks)

    Can I get the Form Title?
    I was able to get form ID but it would be nice to show the Form Title instead.
    And can I also get de $merge_variables in a more readable way? Is there a way to show the variables like:
    Name: XXXX
    email: XXXXX
    etc…
    Thanks

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hey @magaworks,

    Yup, replace your current snippet with this updated one.

     add_action( 'yikes-mailchimp-form-submission', 'yikes_send_email_after_submission', 10, 4 );
    
     function yikes_send_email_after_submission( $email, $merge_variables, $form_id, $notifications ) {
    
     	$interface   = yikes_easy_mailchimp_extender_get_form_interface();
    	$form_data   = $interface->get_form( $form_id );
    	$form_name   = $form_data['form_name'];
    	$content     = '<p>MailChimp Submission for Form: ' . $form_name . '</p>';
     	$content    .= '<p>A user with the email ' . $email . ' has attempted to subscribe to your MailChimp list.</p>';
     	$content    .= '<p>Here is their information: </p><br>'; 
     	foreach ( $merge_variables as $merge_tag => $merge_value ) {
     		$content .= '<p>' . $merge_tag . ': ' . $merge_value . '</p>';
     	}
     	$admin_email = '[email protected]';
     	$subject     = 'New MailChimp Submission for Form: ' . $form_name;
     	$headers     = array( 'Content-Type: text/html; charset=UTF-8' );
    
     	wp_mail( $admin_email, $subject, $content, $headers );
     }
    Thread Starter magaworks

    (@magaworks)

    Hi, thanks for all the help.
    About the form name it is not collecting that part for some reason: $form_name = $form_data[‘form_name’];
    All the rest os perfect.
    Thank you so much for the help

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    What is showing for $form_name? Does it just show “New MailChimp Submission for Form: “?

    Thread Starter magaworks

    (@magaworks)

    It does shoe that sentence too.
    It starts the line below “A user with the email”
    But I am not using the last version of wordpress, let me try updating it first.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Can you make sure you’re using the updated snippet? Can you paste the snippet you’re currently using here?

    Thanks,
    Kevin.

    Thread Starter magaworks

    (@magaworks)

    Sorry,
    Everything works just fin.
    My fault. I miss formated a line when translating to my language.
    Now It all works just Fine!!!
    Thanks a lot again

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

The topic ‘Send email to Admin’ is closed to new replies.