我正致力于将Twilio与Wordpress和Contact form 7插件集成。
我为联系表单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"
)
);
}
答案 0 :(得分:0)
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"
)
);
}
让我知道这是否有帮助。