Contacting You By SMS From Your Website
Enable your site visitors to contact you by sending SMS messages.
Learn how to build a contact form on a website that will send user requests via SMS to a predefined phone number belonging, for example, to the sales or support team.
What does this thing do?
This PHP sample application demonstrates how to create a web contact form that sends SMS to the specified mobile phone number. In this tutorial, we will show you the HTML form that accepts user messages and the code that sends these messages via SMS and checks message delivery statuses by using Apifonica API.
Let’s get started!
An Apifonica account SID and password to send SMS messages from the web.
You can find these in your personal account.
An Apifonica phone number to be the SMS sender’s number.
You can rent a number from your Apifonica account.
- An Apache/nginx HTTP server supporting PHP version 5 or higher and cURL.
Step 1. Get the Code
Click here to download the source (case.php) which includes everything you need for this tutorial.
The file contains an HTTP form to be displayed to site visitors, and also the functions to send user input via SMS messages to the predefined mobile number and check SMS delivery statuses.
The following diagram demonstrates how the sample works.
Step 2. Set Default Variables
In the downloaded case file, specify the default parameter values:
- Your account SID.
- Your account password (authToken).
- A number you have rented from this account—this number will be used as the SMS sender’s number.
- A mobile number to receive SMS messages—this number will be used as recipient’s phone number.
// Specify Apifonica API URL $api_url = 'https://api.apifonica.com'; // Specify your Apifonica account SID $accountSID = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // Specify your Apifonica account password $password = 'XXXXXXXXXXXX'; // Specify the message sender's number (this number must belong to the Apifonica account you have specified) $from = '883XXXXXXXXXXXX'; // Specify the mobile number to receive SMS messages sent from the web form $to = 'XXXXXXXXXX';
Step 3. Upload the Updated Sample File to Your Server
The data you have specified will now be used for sending SMS messages: your Apifonica account will be charged for outgoing SMS messages sent from the web to the predefined mobile number.
Step 4. Open the Web Form on Your Site and Try How It Works
Fill in the fields in the web form and click the Send Your Message button to send the SMS message from the browser.
Step 5. Check the Message Delivery
Click the Update Delivery Status button to see that your message is sent and then delivered to your mobile.