【发布时间】:2017-12-01 05:56:35
【问题描述】:
我正在努力将 Twilio 与 Wordpress 和 Contact form 7 插件集成。
我为 Contact form 7 制作了一个挂钩,以便在提交表单时使用 Twilio 发送短信。有用。
我的下一步是根据收件人发送到不同的号码(我在联系表 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" ) ); } -
这是第二部分,我不能让它工作。
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