{"id":876,"date":"2023-03-09T06:42:46","date_gmt":"2023-03-09T06:42:46","guid":{"rendered":"https:\/\/whatsapp247.com\/blog\/?p=876"},"modified":"2023-03-09T06:52:12","modified_gmt":"2023-03-09T06:52:12","slug":"send-a-message-by-whatsapp-api-using-php","status":"publish","type":"post","link":"https:\/\/msgpk.com\/blog\/?p=876","title":{"rendered":"Send a Message by WhatsApp API using PHP"},"content":{"rendered":"\n<p>In this tutorial, we will create a page to send messages via WhatsApp API using PHP<\/p>\n\n\n\n<p>Before starting, an active account is required (If Not <a rel=\"noreferrer noopener\" href=\"https:\/\/whatsapp247.com\/Register.php\" data-type=\"URL\" data-id=\"https:\/\/whatsapp247.com\/Register.php\" target=\"_blank\">Register<\/a> Your Account), <a rel=\"noreferrer noopener\" href=\"https:\/\/whatsapp247.com\/Login.php\" data-type=\"URL\" data-id=\"https:\/\/whatsapp247.com\/Login.php\" target=\"_blank\">Login<\/a> to your account &amp; get your secret <strong><span style=\"text-decoration: underline;\"><a rel=\"noreferrer noopener\" href=\"https:\/\/whatsapp247.com\/dashboard\/profile_api_key.php\" data-type=\"URL\" data-id=\"https:\/\/whatsapp247.com\/dashboard\/profile_api_key.php\" target=\"_blank\">API_KEY<\/a><\/span><\/strong><\/p>\n\n\n\n<p>First of all we will create a file name function.php, having the following code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nfunction wa($mobile = null, $type = null, $message = null, $priority = null){\n$api_key='';\/\/\/\/YOUR_API_KEY\n\n$curl = curl_init();\n$url = \"http:\/\/whatsapp247.com\/api\/send.php\";\nif($type=='1' || $type=='2'){\n$parameters = array(\"api_key\" =&gt; $api_key, \"type\" =&gt; $type, \"mobile\" =&gt; $mobile, \"url\" =&gt; $message, \"priority\" =&gt; $priority);}else{\n$parameters = array(\"api_key\" =&gt; $api_key, \"type\" =&gt; $type, \"mobile\" =&gt; $mobile, \"message\" =&gt; $message, \"priority\" =&gt; $priority);    \n}\n$ch = curl_init();\n$timeout  =  30;\ncurl_setopt($ch, CURLOPT_URL, $url);\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);\ncurl_setopt($ch, CURLOPT_HEADER, 0);\ncurl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);\ncurl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);\ncurl_setopt($ch, CURLOPT_POST, 1);\ncurl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);\ncurl_setopt($ch, CURLOPT_TIMEOUT, $timeout);\n$response = curl_exec($ch);\ncurl_close($ch);\nreturn $response ;\n}\n?&gt;<\/code><\/pre>\n\n\n\n<p>In line no 3, paste your <a rel=\"noreferrer noopener\" href=\"https:\/\/whatsapp247.com\/dashboard\/profile_api_key.php\" data-type=\"URL\" data-id=\"https:\/\/whatsapp247.com\/dashboard\/profile_api_key.php\" target=\"_blank\">secret API key<\/a><\/p>\n\n\n\n<p>include this file in your PHP page<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>require_once('function.php'); <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Send Text Message<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>echo wa('923XXXXX', '0', 'Hello World', '10');<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized is-style-default\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/whatsapp247.com\/blog\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-112430-1024x214.png\" alt=\"\" class=\"wp-image-879\" width=\"520\" height=\"108\" srcset=\"https:\/\/msgpk.com\/blog\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-112430-1024x214.png 1024w, https:\/\/msgpk.com\/blog\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-112430-300x63.png 300w, https:\/\/msgpk.com\/blog\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-112430-768x161.png 768w, https:\/\/msgpk.com\/blog\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-112430-1536x321.png 1536w, https:\/\/msgpk.com\/blog\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-112430.png 1635w\" sizes=\"auto, (max-width: 520px) 100vw, 520px\" \/><figcaption class=\"wp-element-caption\">Parameters Description: <a href=\"https:\/\/whatsapp247.com\/api.php\" data-type=\"URL\" data-id=\"https:\/\/whatsapp247.com\/api.php\" target=\"_blank\" rel=\"noreferrer noopener\">Refference<\/a><\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Send Image Message<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>echo wa('923XXXXX', '1', 'https:\/\/sample-videos.com\/img\/Sample-jpg-image-50kb.jpg', '10');<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Send Document Message<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>echo wa('923XXXX', '2', 'https:\/\/www.africau.edu\/images\/default\/sample.pdf', '10');<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Send Audio \/ Voice Message<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>echo wa('923XXXX', '2', 'https:\/\/file-example.s3-accelerate.amazonaws.com\/voice\/oog_example.ogg', '10');<\/code><\/pre>\n\n\n\n<p>Download Sample Code: <strong><span style=\"text-decoration: underline;\"><a href=\"https:\/\/whatsapp247.com\/dashboard\/app-assets\/php-api.zip\" data-type=\"URL\" data-id=\"https:\/\/whatsapp247.com\/dashboard\/app-assets\/php-api.zip\" target=\"_blank\" rel=\"noreferrer noopener\">Download<\/a><\/span><\/strong><br><br><br>For More Details, Please Visit Our WhatsApp API <strong><span style=\"text-decoration: underline;\"><a rel=\"noreferrer noopener\" href=\"https:\/\/whatsapp247.com.com\/api.php\" data-type=\"URL\" data-id=\"https:\/\/whatsapp247.com.com\/api.php\" target=\"_blank\">Documentation<\/a><\/span><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will create a page to send messages via WhatsApp API using PHP Before starting, an active account is required (If Not<\/p>\n","protected":false},"author":1,"featured_media":883,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[51,54,52,53],"class_list":["post-876","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorial","tag-api","tag-api-tutorial","tag-php","tag-whatsapp-php"],"_links":{"self":[{"href":"https:\/\/msgpk.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/876","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/msgpk.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/msgpk.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/msgpk.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/msgpk.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=876"}],"version-history":[{"count":5,"href":"https:\/\/msgpk.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/876\/revisions"}],"predecessor-version":[{"id":885,"href":"https:\/\/msgpk.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/876\/revisions\/885"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/msgpk.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/883"}],"wp:attachment":[{"href":"https:\/\/msgpk.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/msgpk.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/msgpk.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}