Send SMS through the website (Front-end)

Updated on Mar 08, 2022

By registering the following shortcode in your functions.php the theme, you can show the send SMS form for your visitors by this shortcode: [wpsms_send_form]

The receiver of SMS is the admin mobile number, you can change the receiver number if you wish!

add_shortcode('wpsms_send_form', function () {
    ?>
    <form method="post">
        <?php wp_nonce_field('send_sms_nonce', 'wpsms_nonce'); ?>
        <textarea name="content"></textarea>
        <button type="submit">Send SMS!</button>
    </form>
    <?php
    if (isset($_POST['wpsms_nonce']) && wp_verify_nonce($_POST['wpsms_nonce'], 'send_sms_nonce')) {
        $adminMobileNumber[] = \WP_SMS\Option::getOption('admin_mobile_number');
        wp_sms_send($adminMobileNumber, sanitize_text_field($_POST['content']));
        wp_safe_redirect( wp_get_referer() );
        exit;
    }
});