Best mobile app development and design company Best e commerce development company Send SMS when submitting Contact Form 7 in WordPress

Send SMS when submitting Contact Form 7 in WordPress.

Contact Form 7 is one of the most popular plugins for creating and managing forms in WordPress. The plugin provides the provision for managing the fields. Thus it provides an option for sending the email notification to the given mail address. Sending an SMS notification when submitting the contact form 7 in WordPress is also one of its many features. The requirement specified by our client was that, when the contact form is submitted, an SMS alert is sent to the specified phone number.

So, to satisfy our client’s request we used Twilio. Twilio is one of the cloud communication platforms that help developers to programmatically make/receive calls, and send/receive messages using APIs. For these purposes, we are using the WP SMS wordpress plugin. Integrating Contact Form 7 and the WP SMS plugin for sending an SMS notification in WordPress is very easy.

Steps:-

  1. Install the Contact Form 7 and the WP sms plugin.
  2. Configure the email settings in the cf7 plugin.
  3. Create an account on Twilio(https://www.twilio.com/).
  4. Purchase a phone number.

Steps to integrate the CF7 and the WP SMS:-

  1. Go to the admin dashboard.
  2. Download the WP SMS wordpress plugin(https://wordpress.org/plugins/wp-twilio-core/).
  3. Open the WPSMS menu from the left sidebar of the admin dashboard.
  4. In the Settings tab fill the following details:-
    • Account SID(Available from within your Twilio account).
    • Auth Token(Available from within your Twilio account).
    • Service ID(Available from within your Twilio account It’s required for bulk SMS).
    • Twilio Number(Must be a valid number associated with your Twilio account).
  5. There is a Test tab for testing. In this give a number, message, and click send.
  6. And the Logs tab for viewing the logs.
  7. The Apps & Integration section provides the Additional features(Needs to upgrade to the pro version).

The free version of WP SMS does not provide the facility to integrate the cf 7 plugin. The additional features are only available in the pro version. So we have to add the filters for performing the additional functionality.

Code:-

function custom_wpcf7_mail_sent( $contact_form )
 {
$values_list = $_POST['Phone'];
$number_to = sanitize_text_field( $values_list );
$shortenurl = true;
$message_txt = "test";
twl_send_sms( array( 'number_to' => $number_to, 'message' => $message_txt, 'shortenurl' => $shortenurl ) );
}
add_filter( 'wpcf7_mail_sent', 'custom_wpcf7_mail_sent' );

Paste the above code in functions.php of your theme file. ‘Custom_wpcf7_mail_sent’ is the custom function triggered when a CF7 submission is successful. Hence, the above function retrieves the phone number entered by the user in the form and assigns it to the $number_to variable. It also sets the $shortenurl variable to true and the $message_txt variable to “test”. The ‘twl_send_sms’ function, passes in an array that includes the recipient’s phone number, the message text, and whether or not to shorten the URL (if any URLs are included in the message).

For various WordPress-related services and support reach out to Sreyas. We provide our services all over Europe and worldwide. Our diligent staff committed to satisfying our client requirements.

Recent Blogs


Posted

in

,

by

Tags:

To Know Us Better

Browse through our work.

Explore The Technology Used

Learn about the cutting-edge technology and techniques we use to create innovative software solutions.