联系表格7到PHP SMS发件人

时间:2014-11-21 15:42:25

标签: php wordpress sms contact-form contact-form-7

我使用联系表格7表格来抓住现场电话中的用户电话号码,向他发送短信提醒,如下所示:

<p>Your phone number<br />
    [text* phone] </p>

<p>[submit "Send"]</p>

在我的Wordpress主题的功能中,我有以下内容:

add_action( 'wpcf7_mail_sent', 'your_wpcf7_mail_sent_function' );
function your_wpcf7_mail_sent_function( $contact_form ) {
    $title = $contact_form->title;
    $posted_data = $contact_form->posted_data;

    if ( 'smsservice' == $title ) {

        $phone = $posted_data['phone'];
        require_once 'http://myurl.com/smsservice/send_sms.php';
    }
}

在链接send_sms.php中我得到了:

  # Modify these values to your needs
  $username             = 'myusername';
  $pass                 = 'mypassword';
  $gateway_url          = 'api-adress';

  $utf8_message_text    = "This is a test sms!";
  $recipientAddressList = array['$phone']


  $maxSmsPerMessage     = 1; 
  $test                 = false; // true: do not send sms for real, just test interface

  try {

    // 1.) -- create sms client (once) ------
    $smsClient = new WebSmsCom_Client($username, $pass, $gateway_url);
    //$smsClient->setVerbose(true);

    // 2.) -- create text message ----------------
    $message  = new WebSmsCom_TextMessage($recipientAddressList, $utf8_message_text);
    //$message = binary_sms_sample($recipientAddressList);

    // 3.) -- send message ------------------
    $Response = $smsClient->send($message, $maxSmsPerMessage, $test);

但是,每次填写表单时,它都不会执行任何操作。甚至没有发送表格。但是,从PHP代码我似乎无法找到错误。还有别人吗?

祝你好运, SEB

2 个答案:

答案 0 :(得分:0)

如果您使用的是联系表格7的3.9或更高版本,则不推荐使用published_data属性。见下文:

/* WPCF7_ContactForm object no longer has a posted_data property. */
$posted_data = $contact_form->posted_data; // Wrong.

/* Use WPCF7_Submission object's get_posted_data() method to get it. */
$submission = WPCF7_Submission::get_instance();

if ( $submission ) {
    $posted_data = $submission->get_posted_data();
}

自3.9版以来,标题属性也无法访问。见下文:

/* Don't do this, since title property is no longer accessible. */
$id = $contact_form->title; // Wrong.

/* Use id() method instead. */
$id = $contact_form->title();

在您的情况下,您的功能将是:

function your_wpcf7_mail_sent_function( $contact_form ) {

    $title = $contact_form->title();
    $submission = WPCF7_Submission::get_instance();

    if ( $submission ) {
        $posted_data = $submission->get_posted_data();
    }

    if ( 'smsservice' == $title ) {
        $phone = $posted_data['phone'];
        require_once 'http://myurl.com/smsservice/send_sms.php';
    }

}

要查看联系表单7中的所有更改,请检查changelog

答案 1 :(得分:0)

即使我尝试过相同的但是联系表格7对于短信提醒似乎不是一个好选择。

在我的情况下,我使用了能够完美运行的重力形式。