【问题标题】:Send sms to different numbers based on the recipient Twilio and Contact form 7 - Wordpress根据收件人 Twilio 和联系表 7 向不同号码发送短信 - Wordpress
【发布时间】:2017-12-01 05:56:35
【问题描述】:

我正在努力将 Twilio 与 Wordpress 和 Contact form 7 插件集成。

我为 Contact form 7 制作了一个挂钩,以便在提交表单时使用 Twilio 发送短信。有用。

我的下一步是根据收件人发送到不同的号码(我在联系表 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'] = "bla@bla.com") {
            $to = '+1XXXXXXXXX';
        } else if($WPCF7_ContactForm->mail['recipient'] = "blabla@blabla.com") {
            $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"   
           )
        );
    }
    

【问题讨论】:

    标签: wordpress twilio contact-form-7


    【解决方案1】:

    这里是 Twilio 开发者宣传员。

    从我从其他 Stack Overflow 和 Stack Exchange 问题中可以看出,您实际上已将表单传递给 wpcf7_mail_sent 挂钩,因此您不需要像您一直在尝试的那样需要这两个挂钩。像下面这样的东西应该可以工作:

    add_action( 'wpcf7_mail_sent', 'your_wpcf7_mail_sent_function' );
    function your_wpcf7_mail_sent_function($cf7form) {
        if ($cf7form->mail['recipient'] = "bla@bla.com") {
            $to = '+1XXXXXXXXX';
        } else if($cf7form->mail['recipient'] = "blabla@blabla.com") {
            $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"   
            )
        );
    }
    

    让我知道这是否有帮助。

    【讨论】:

      猜你喜欢
      • 2016-03-15
      • 2014-02-16
      • 2011-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-03
      • 1970-01-01
      相关资源
      最近更新 更多