2017-12-01 19 views
0

TwilioとWordpressおよびContactフォーム7プラグインを統合する作業を進めています。受信者Twilioと連絡先フォーム7 - Wordpressに基づいて別の番号にSMSを送信

連絡先フォーム7のフックを作成し、フォーム提出時にTwilioとSMSを送信しました。できます。

私の次のステップは、受信者に基づいて異なる番号に送信することです(連絡先フォーム7に3つの異なる場所があり、受信者は選択した場所に基づいて変更されます)。

私はそれを動作させることはできません。

以下は私のコードですが、どのような考えですか?

  1. このフック作品や1つの番号のみ

    add_action('wpcf7_mail_sent', 'your_wpcf7_mail_sent_function'); 
    function your_wpcf7_mail_sent_function() { 
        $sid = 'xxx'; 
        $token = 'xxx'; 
        $client = new Client($sid, $token); 
        $to = '+1111111111'; 
    
    
    $client->messages->create(
    // the number you'd like to send the message to 
        $to, 
        array( 
        'from' =>'+1212121211', 
        'body' => "form submitted" 
        ) 
    ); 
    } 
    
  2. これは、第二部であるに送信し、私はそれを動作させることはできません。ここ

    global $to; 
    function wpcf7_do_something (&$WPCF7_ContactForm) { 
        if ($WPCF7_ContactForm->mail['recipient'] = "[email protected]") { 
         $to = '+1XXXXXXXXX'; 
        } else if($WPCF7_ContactForm->mail['recipient'] = "[email protected]") { 
         $to = '+1x1x1x1x1x'; 
        } else { 
         $to = "+1000000000" 
        } 
    } 
    add_action('wpcf7_before_send_mail', 'wpcf7_do_something'); 
    
    add_action('wpcf7_mail_sent', 'your_wpcf7_mail_sent_function'); 
    
    function your_wpcf7_mail_sent_function() { 
        $sid = 'xxxxxxx'; 
        $token = 'xxxxxxx'; 
        $client = new Client($sid, $token); 
    
    
    
        $client->messages->create(
        // the number you'd like to send the message to 
         $to, 
         array( 
          'from' =>'+1XXXXXXXXX', 
          'body' => "form submitted" 
         ) 
        ); 
    } 
    

答えて

0

Twilioの開発者エバンジェリスト。

他のスタックオーバーフローとスタック交換の質問からわかるように、実際にフォームはwpcf7_mail_sentフックに渡されるので、2つのフックは必要ありません。次のようなものがうまくいくはずです。

add_action('wpcf7_mail_sent', 'your_wpcf7_mail_sent_function'); 
function your_wpcf7_mail_sent_function($cf7form) { 
    if ($cf7form->mail['recipient'] = "[email protected]") { 
     $to = '+1XXXXXXXXX'; 
    } else if($cf7form->mail['recipient'] = "[email protected]") { 
     $to = '+1x1x1x1x1x'; 
    } else { 
     $to = "+1000000000" 
    } 

    $sid = 'xxx'; 
    $token = 'xxx'; 
    $client = new Client($sid, $token); 

    $client->messages->create(
    // the number you'd like to send the message to 
     $to, 
     array( 
      'from' =>'+1212121211', 
      'body' => "form submitted" 
     ) 
    ); 
} 

それがまったく役に立ったら教えてください。

関連する問題