-4

Im using this code to subscribe user to MailerLiteusing contact form 7 if i hard code email value it is adding user to MailerLite subscription list on submit but it did not work with posted data values.

it seems like get_posted_data(); not returning values.

<?php 


$current_path = getcwd();
require("$current_path/wp-load.php");

require_once 'vendor/autoload.php';
use MailerLite\Campaigns;


add_action( 'wpcf7_mail_sent', 'your_wpcf7_mail_sent_function' ); 

function your_wpcf7_mail_sent_function( $contact_form ) {



    $title = $contact_form->title;
    $submission = WPCF7_Submission::get_instance();

    if ( $submission ) {

        $posted_data = $submission->get_posted_data();



         $name = $posted_data['your-name'];
         $email = $posted_data['your-email'];



        $ML_Subscribers = new MailerLite\Subscribers( '453453453' );

        $subscriber = array(
            'email' => $name,
            'name' =>  $email,

        );
        $subscriber = $ML_Subscribers->setId( '4014513' )->setAutoresponders(false)->add( $subscriber );



    }


}
2
  • someone down vote this in first look can you pls comment what is wrong this question i came here after research many blogs but this problem was not solved. Jun 2 '16 at 6:30
  • It's probably being downvoted because WPSE isn't meant to be used for Third-Party Plugins Jun 2 '16 at 9:44
-1

Let's try debug $posted_data with sending email

if ( $submission ) {

    $posted_data = $submission->get_posted_data(); 

    ob_start(); 

    echo '<pre>';
    print_r($posted_data);
    echo '</pre>';

    $content = ob_get_clean();

    wp_mail($your_mail, 'Debug', $content);

or you can save $content to file

5
  • Thanks Nefro this is output so get_posted_data return data. but why it is not working in my function. <pre>Array ( [_wpcf7] => 207 [_wpcf7_version] => 4.4.2 [_wpcf7_locale] => en_US [_wpcf7_unit_tag] => wpcf7-f207-p5-o1 [your-name] => shahid [your-email] => shahid.cohdy@gmail.com [_wpcf7_is_ajax_call] => 1 ) </pre> Jun 2 '16 at 6:47
  • i was try to debug with session but it is not working in wp. Jun 2 '16 at 6:49
  • your $posted_data seems good, I think problem will be with "MailerLite", lets try $content = ob_get_clean(); use at the end of function with enable wordpress and PHP debug
    – Nefro
    Jun 2 '16 at 6:51
  • This is insane i was using 'email' => $name, instead 'email' => $email, debugging solve my problem i spend 4 hour to debug posted data with cookies and session. :) Thanks a lot. Jun 2 '16 at 6:57
  • I'm upvoting this, not because it is the answer, but because it is a good way to see what your $posted_data array contains. Recommended in terms of getting some output for guidance.
    – RiaanP
    May 6 '20 at 6:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.