2017-12-01 1 views
0

Twilio를 Wordpress 및 연락처 양식 7 플러그인과 통합하려고합니다.받는 사람 Twilio 및 연락처 양식 7 - Wordpress에 따라 다른 번호로 SMS 보내기

양식 제출시 Twilio와 함께 SMS를 보내려면 Contact 양식 7에 후크를 만들었습니다. 그것은 작동합니다.

내 다음 단계는 수신자를 기반으로 다른 번호로 전송하는 것입니다 (연락처 양식 7에 3 개의 다른 위치가 있고 선택한 위치에 따라받는 사람이 변경됨).

나는 제대로 작동하지 않습니다.

아래 코드는 어떤 생각입니까?

  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 후크로 전달하므로 시도한 것처럼 두 갈고리가 필요하지 않습니다. 다음과 같은 것이 작동해야합니다.

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" 
     ) 
    ); 
} 

전혀 도움이되는지 알려주세요.

관련 문제