将联系表7数据发送到Infusionsoft

时间:2018-08-06 14:37:43

标签: wordpress curl infusionsoft

我在Wordpress多站点上使用联系表格7。我想要一种情况,例如用户填写此表格时,数据将通过电子邮件发送给admin,同样的数据也会发送给infusionsoft联系人。尝试过以下“ CURL”操作。但是它会引发类似“卷曲错误:跟随最大(20)个重定向”的错误。

我已将此代码放置在functions.php文件中...我正在为多站点工作,因此“ $ app_id”和“ $ form_id”将动态出现
  

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

$app_id =  get_field('app_id', 'options'); 
$form_id =  get_field('form_id', 'options'); 



if ( $submission ) {

    $posted_data = $submission->get_posted_data();
}

    function post_to_url($url, $data) {

    $fields = '';
    foreach($data as $key => $value) {
    $fields .= $key . '=' . $value . '&';
    }

    rtrim($fields, '&');
    $timeout = 30;
    $post = curl_init();  

    curl_setopt($post, CURLOPT_URL, $url);
    curl_setopt($post, CURLOPT_HEADER, 0);
    curl_setopt ($post, CURLOPT_TIMEOUT, $timeout);
    curl_setopt ($post, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
    curl_setopt ($post, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt ($post, CURLOPT_SSL_VERIFYHOST,  2);
    curl_setopt($post, CURLOPT_POST, true);
    curl_setopt($post, CURLOPT_POSTFIELDS, ($fields));
    curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($post, CURLOPT_FOLLOWLOCATION, 1);

    $result = curl_exec($post);

    if(!curl_exec($post)){
        die('Error: "' . curl_error($post) . '" - Code: ' . curl_errno($post));
    }
    curl_close($post);
    }

   if ( 'some title' == $title ) {

    $data = array(
    "inf_field_FirstName" =>  $posted_data['fname'],
    "inf_field_Email" =>      $posted_data['email'],
    "inf_field_LastName" =>   $posted_data['lname'],
    "inf_field_Phone2" =>     $posted_data['telephone'],
    "inf_custom_City0" =>     $posted_data['city'],
    "inf_custom_ZipCode" =>   $posted_data['zip'],
    "inf_custom_Ihavequestionsabout" =>   $posted_data['comments'],
    "inf_form_xid" =>        $form_id,
    "inf_form_name" =>       "Web Form submitted",
    "infusionsoft_version" => "1.70.0.58116"        
    );

    $final_url = "https://".$app_id.".infusionsoft.com/app/form/process/".$form_id; 
   post_to_url($final_url, $data);

  }
}

0 个答案:

没有答案