【问题标题】:Contact Form 7 to PHP SMS Sender联系表格 7 到 PHP 短信发件人
【发布时间】:2014-11-28 14:58:12
【问题描述】:

我使用 Contact Form 7 表单在外业电话中捕获用户的电话号码,以向他发送 SMS 提醒,如下所示:

<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 代码中我似乎找不到错误。还有人吗?

最好的问候, 赛博

【问题讨论】:

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


    【解决方案1】:

    如果您使用的是 3.9 版或更高版本的 Contact Form 7,则不推荐使用 posted_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();
    }
    

    此外,title 属性自 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

    【讨论】:

      【解决方案2】:

      好吧,即使我也尝试过,但联系表格 7 似乎不是 SMS 警报的好选择。

      在我的例子中,我使用了非常有效的重力形式。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-28
        • 2012-08-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多