联系人表单7 GET_POSTED_DATA();未返回已发布的值

时间:2016-06-02 作者:Shahid Chaudhary

Im使用此代码向用户订阅MailerLite使用联系表单7如果我硬编码电子邮件值,则在提交时会将用户添加到MailerLite订阅列表,但它不适用于发布的数据值。

看起来像是get_posted_data(); 不返回值。

<?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 );



    }


}

1 个回复
最合适的回答,由SO网友:Nefro 整理而成

让我们尝试调试$posted_data 通过发送电子邮件

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);
或者您可以保存$content 到文件

相关推荐