{"id":245,"date":"2020-06-09T07:12:44","date_gmt":"2020-06-09T07:12:44","guid":{"rendered":"https:\/\/codexjunction.com\/?p=245"},"modified":"2023-10-29T16:52:07","modified_gmt":"2023-10-29T16:52:07","slug":"sms-integration-in-wordpress-using-php-without-plugin","status":"publish","type":"post","link":"https:\/\/codexjunction.com\/sms-integration-in-wordpress-using-php-without-plugin\/","title":{"rendered":"SMS Integration in WordPress using PHP (Without Plugin)"},"content":{"rendered":"<p data-sourcepos=\"1:1-1:80\">To integrate SMS in WordPress without a plugin, you can use the following steps:<\/p>\n<ol data-sourcepos=\"3:1-9:0\">\n<li data-sourcepos=\"3:1-3:205\"><strong>Choose an SMS gateway.<\/strong>\u00a0There are many different SMS gateways available, so you will need to choose one that is compatible with your needs. Some popular SMS gateways include Twilio, Nexmo, and Plivo.<\/li>\n<li data-sourcepos=\"4:1-4:204\"><strong>Create an account with the SMS gateway.<\/strong>\u00a0Once you have chosen an SMS gateway, you will need to create an account. This will give you access to the API that you will need to use to send SMS messages.<\/li>\n<li data-sourcepos=\"5:1-5:198\"><strong>Install the PHP SMS library.<\/strong>\u00a0There are a few different PHP SMS libraries available, so you can choose one that is compatible with your needs. One popular PHP SMS library is called PHP Twilio.<\/li>\n<li data-sourcepos=\"6:1-6:155\"><strong>Configure the PHP SMS library.<\/strong>\u00a0Once you have installed the PHP SMS library, you will need to configure it with your SMS gateway account information.<\/li>\n<li data-sourcepos=\"7:1-7:203\"><strong>Write the code to send SMS messages.<\/strong>\u00a0Once you have configured the PHP SMS library, you can write the code to send SMS messages. This code will vary depending on the SMS gateway that you are using.<\/li>\n<li data-sourcepos=\"8:1-9:0\"><strong>Integrate the code into your WordPress theme or plugin.<\/strong>\u00a0Once you have written the code to send SMS messages, you can integrate it into your WordPress theme or plugin. This will allow you to send SMS messages from your WordPress website.<\/li>\n<\/ol>\n<p data-sourcepos=\"10:1-10:78\">Here is an example of how to send an SMS message using the PHP Twilio library:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<div class=\"code-block-decoration header gmat-subhead-2 ng-star-inserted\">PHP<\/div>\n<pre><code class=\"code-container\" role=\"text\"><span class=\"hljs-meta\">&lt;?php<\/span>\r\n\r\n<span class=\"hljs-comment\">\/\/ Include the PHP Twilio library.<\/span>\r\n<span class=\"hljs-keyword\">require_once<\/span> <span class=\"hljs-string\">'Twilio\/autoload.php'<\/span>;\r\n\r\n<span class=\"hljs-comment\">\/\/ Create a new Twilio client.<\/span>\r\n<span class=\"hljs-variable\">$client<\/span> = <span class=\"hljs-keyword\">new<\/span> Twilio\\Rest\\Client(<span class=\"hljs-string\">'YOUR_TWILIO_ACCOUNT_SID'<\/span>, <span class=\"hljs-string\">'YOUR_TWILIO_AUTH_TOKEN'<\/span>);\r\n\r\n<span class=\"hljs-comment\">\/\/ Create a new SMS message.<\/span>\r\n<span class=\"hljs-variable\">$message<\/span> = <span class=\"hljs-variable\">$client<\/span>-&gt;messages-&gt;create(\r\n    <span class=\"hljs-string\">'+15555555555'<\/span>, <span class=\"hljs-comment\">\/\/ The recipient's phone number.<\/span>\r\n    <span class=\"hljs-keyword\">array<\/span>(\r\n        <span class=\"hljs-string\">'from'<\/span> =&gt; <span class=\"hljs-string\">'+15555555555'<\/span>, <span class=\"hljs-comment\">\/\/ The sender's phone number.<\/span>\r\n        <span class=\"hljs-string\">'body'<\/span> =&gt; <span class=\"hljs-string\">'This is a test SMS message.'<\/span>, <span class=\"hljs-comment\">\/\/ The message body.<\/span>\r\n    )\r\n);\r\n\r\n<span class=\"hljs-comment\">\/\/ Print the message ID.<\/span>\r\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-variable\">$message<\/span>-&gt;sid;\r\n\r\n<span class=\"hljs-meta\">?&gt;<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"36:1-36:205\">You can integrate this code into your <a href=\"https:\/\/codexjunction.com\/error-establishing-database-connection-wordpress\/\">WordPress theme<\/a> or plugin by adding it to a function file. Once you have added the code, you can send SMS messages from your WordPress website by calling the function.<\/p>\n<p data-sourcepos=\"38:1-38:130\">For example, the following code would send an SMS message to the phone number <code>+15555555555<\/code> with the message body &#8220;Hello world!&#8221;:<\/p>\n<div class=\"code-block ng-star-inserted\">\n<div class=\"code-block-decoration header gmat-subhead-2 ng-star-inserted\">PHP<\/div>\n<pre><code class=\"code-container\" role=\"text\"><span class=\"hljs-meta\">&lt;?php<\/span>\r\n\r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">send_sms_message<\/span>() <\/span>{\r\n    <span class=\"hljs-comment\">\/\/ Include the PHP Twilio library.<\/span>\r\n    <span class=\"hljs-keyword\">require_once<\/span> <span class=\"hljs-string\">'Twilio\/autoload.php'<\/span>;\r\n\r\n    <span class=\"hljs-comment\">\/\/ Create a new Twilio client.<\/span>\r\n    <span class=\"hljs-variable\">$client<\/span> = <span class=\"hljs-keyword\">new<\/span> Twilio\\Rest\\Client(<span class=\"hljs-string\">'YOUR_TWILIO_ACCOUNT_SID'<\/span>, <span class=\"hljs-string\">'YOUR_TWILIO_AUTH_TOKEN'<\/span>);\r\n\r\n    <span class=\"hljs-comment\">\/\/ Create a new SMS message.<\/span>\r\n    <span class=\"hljs-variable\">$message<\/span> = <span class=\"hljs-variable\">$client<\/span>-&gt;messages-&gt;create(\r\n        <span class=\"hljs-string\">'+15555555555'<\/span>, <span class=\"hljs-comment\">\/\/ The recipient's phone number.<\/span>\r\n        <span class=\"hljs-keyword\">array<\/span>(\r\n            <span class=\"hljs-string\">'from'<\/span> =&gt; <span class=\"hljs-string\">'+15555555555'<\/span>, <span class=\"hljs-comment\">\/\/ The sender's phone number.<\/span>\r\n            <span class=\"hljs-string\">'body'<\/span> =&gt; <span class=\"hljs-string\">'Hello world!'<\/span>, <span class=\"hljs-comment\">\/\/ The message body.<\/span>\r\n        )\r\n    );\r\n\r\n    <span class=\"hljs-comment\">\/\/ Print the message ID.<\/span>\r\n    <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-variable\">$message<\/span>-&gt;sid;\r\n}\r\n\r\n<span class=\"hljs-comment\">\/\/ Send the SMS message.<\/span>\r\nsend_sms_message();\r\n\r\n<span class=\"hljs-meta\">?&gt;<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p data-sourcepos=\"69:1-69:252\">This is just a basic example of how to send SMS messages from <a href=\"https:\/\/stackoverflow.com\/questions\/43972089\/how-to-insert-php-script-into-a-wordpress-without-using-a-plugin\" rel=\"nofollow\">WordPress using PHP without a plugin<\/a>. You can use the same approach to send SMS messages from specific events in WordPress, such as when a new post is published or when a new user registers.<\/p>\n<p data-sourcepos=\"71:1-71:64\">Here are some ideas for how to use SMS integration in WordPress:<\/p>\n<ul data-sourcepos=\"73:1-79:0\">\n<li data-sourcepos=\"73:1-73:63\">Send SMS notifications to users when new posts are published.<\/li>\n<li data-sourcepos=\"74:1-74:67\">Send SMS notifications to users when their comments are approved.<\/li>\n<li data-sourcepos=\"75:1-75:64\">Send SMS notifications to users when their orders are shipped.<\/li>\n<li data-sourcepos=\"76:1-76:72\">Send SMS notifications to users when their appointments are confirmed.<\/li>\n<li data-sourcepos=\"77:1-77:31\">Send SMS marketing campaigns.<\/li>\n<li data-sourcepos=\"78:1-79:0\">Send SMS alerts to administrators when there are problems with the website.<\/li>\n<\/ul>\n<p data-sourcepos=\"80:1-80:30\">The possibilities are endless!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To integrate SMS in WordPress without a plugin, you can use the following steps: Choose an SMS gateway.\u00a0There are many different SMS gateways available, so you will need to choose one that is compatible with your needs. Some popular SMS gateways include Twilio, Nexmo, and Plivo. Create an account with the SMS gateway.\u00a0Once you have chosen an SMS gateway, you will need to create an account. This will give you access to the API that you will need to use to send SMS messages. Install the PHP SMS library.\u00a0There are a few different PHP SMS libraries available, so you can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":287,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[512,508,510,511,509,257],"class_list":["post-245","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-a-online-course-web-tutorial","tag-learn-java-online","tag-learn-laravel-online","tag-learn-php-online","tag-learn-python-online","tag-sms-integration"],"_links":{"self":[{"href":"https:\/\/codexjunction.com\/wp-json\/wp\/v2\/posts\/245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codexjunction.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codexjunction.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codexjunction.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codexjunction.com\/wp-json\/wp\/v2\/comments?post=245"}],"version-history":[{"count":4,"href":"https:\/\/codexjunction.com\/wp-json\/wp\/v2\/posts\/245\/revisions"}],"predecessor-version":[{"id":2662,"href":"https:\/\/codexjunction.com\/wp-json\/wp\/v2\/posts\/245\/revisions\/2662"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexjunction.com\/wp-json\/wp\/v2\/media\/287"}],"wp:attachment":[{"href":"https:\/\/codexjunction.com\/wp-json\/wp\/v2\/media?parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexjunction.com\/wp-json\/wp\/v2\/categories?post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexjunction.com\/wp-json\/wp\/v2\/tags?post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}