{"_id":"56b3240705daaa2300363143","category":{"_id":"56b22a9665ddf50d0076ba40","version":"568fce2b04440a1700e4cb4a","pages":[],"project":"568fce2a04440a1700e4cb47","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-03T16:28:06.358Z","from_sync":false,"order":4,"slug":"php-quickstarts","title":"PHP Quickstarts"},"project":"568fce2a04440a1700e4cb47","__v":4,"version":{"_id":"568fce2b04440a1700e4cb4a","project":"568fce2a04440a1700e4cb47","__v":20,"createdAt":"2016-01-08T14:56:43.101Z","releaseDate":"2016-01-08T14:56:43.101Z","categories":["568fce2b04440a1700e4cb4b","568fd1b8b700ce0d002f4b1c","568fd23804440a1700e4cb5b","568fd2444719c119002ce5d8","568ff21204440a1700e4cbc1","5693732c8aa8040d009f2c28","5693738393445b0d00abdad0","5693740093445b0d00abdad1","56937445974aaa0d001ca699","5693b82173f48f0d0075c90d","5694c4cd1005590d0062cb25","569f854466a5640d00efa54c","56a264cdd15dd70d008d825b","56aa56bf318e6c1700a19ddb","56b0e6347ae4550d000627bd","56b200c0f48f270d00e0de6f","56b200c6f48f270d00e0de70","56b22a9665ddf50d0076ba40","56e92ef71996862200fd7f42","574d6577fb835c0e00ca316a"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"parentDoc":null,"user":"55116f88e2990b0d00fb0552","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-04T10:12:23.484Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Note\",\n  \"body\": \"You will need a Dynmark long number or shortcode keyword attached to your account to be able to work through this quickstart.\"\n}\n[/block]\nIn the last Receive SMS Messages quickstart, we processed sent message receipts. Now that our target audience has received a message, they're going to want to reply. We can handle the replies using Inbound Message Forwarding.\n\nSimilar to the last sample, we're going to create an inbound message handler that logs each message to an in memory data store.\n\n1.Create InboundHandler.php which will receive and process inbound messages\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\nini_set('display_errors', 'On');\\n\\nparse_str($_SERVER[\\\"QUERY_STRING\\\"], $request);\\n\\nif (!isset($_SESSION['InboundStore'])) {\\n  $_SESSION['InboundStore'] = array();\\n}\\n\\n$messageId = (int)$request[\\\"msgid\\\"];\\n\\n$_SESSION['InboundStore'][$messageId] =\\n[\\n    \\\"MessageId\\\" => $messageId,\\n    \\\"Date\\\" => DateTime::createFromFormat('d M Y H:i:s', $request[\\\"datetime\\\"]),\\n    \\\"Recipient\\\" => $request[\\\"recipient\\\"],\\n    \\\"Sender\\\" => $request[\\\"sender\\\"],\\n    \\\"Body\\\" => $request[\\\"content\\\"]\\n];\\n\\n?>\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nWe log the date the Dynmark generated numeric message id, the date the message arrived, the phone number that the message was from, the Dynmark long number it was sent to and the body of the message.\n\nWe now need to enable the sending of inbound messages to our new handler by visiting the Dynmark User Portal [Inbound Settings](https://apps.dynmark.com/DD/UserPortal/Home/IncomingForwarding) page and adding your inbound message handler endpoint to the Dynmark long number or keyword.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Note\",\n  \"body\": \"The inbound message handler endpoint specified must be publicly accessible\"\n}\n[/block]\n3. Add a view page called InboundViewer.php which will allow us to view the messages we've received.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<table>\\n    <tr>\\n        <th>MessageId</th>\\n        <th>Date</th>\\n        <th>Sender</th>\\n        <th>Recipient</th>\\n        <th>Body</th>\\n    </tr>\\n<?php    \\n    session_start();\\n\\n    parse_str($_SERVER[\\\"QUERY_STRING\\\"], $request);\\n    \\n    foreach ($_SESSION[\\\"InboundStore\\\"] as $inbound)\\n    {\\n        echo \\\"<tr>\\\";\\n            echo \\\"<td>\\\" . $inbound[\\\"MessageId\\\"] . \\\"</td>\\\";\\n            echo \\\"<td>\\\" . date_format($inbound[\\\"Date\\\"], 'Y-m-d H:i:s') . \\\"</td>\\\";\\n            echo \\\"<td>\\\" . htmlentities($inbound[\\\"Sender\\\"]) . \\\"</td>\\\";\\n            echo \\\"<td>\\\" . $inbound[\\\"Recipient\\\"] . \\\"</td>\\\";\\n            echo \\\"<td>\\\" . htmlentities($inbound[\\\"Body\\\"]) . \\\"</td>\\\";\\n        echo \\\"</tr>\\\";        \\n    }\\n?>\\n</table>\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]","excerpt":"Receiving text messages via inbound message forwarding","slug":"qs-php-receive-sms-messages","type":"basic","title":"Receive SMS Messages"}

Receive SMS Messages

Receiving text messages via inbound message forwarding

[block:callout] { "type": "info", "title": "Note", "body": "You will need a Dynmark long number or shortcode keyword attached to your account to be able to work through this quickstart." } [/block] In the last Receive SMS Messages quickstart, we processed sent message receipts. Now that our target audience has received a message, they're going to want to reply. We can handle the replies using Inbound Message Forwarding. Similar to the last sample, we're going to create an inbound message handler that logs each message to an in memory data store. 1.Create InboundHandler.php which will receive and process inbound messages [block:code] { "codes": [ { "code": "<?php\n\nini_set('display_errors', 'On');\n\nparse_str($_SERVER[\"QUERY_STRING\"], $request);\n\nif (!isset($_SESSION['InboundStore'])) {\n $_SESSION['InboundStore'] = array();\n}\n\n$messageId = (int)$request[\"msgid\"];\n\n$_SESSION['InboundStore'][$messageId] =\n[\n \"MessageId\" => $messageId,\n \"Date\" => DateTime::createFromFormat('d M Y H:i:s', $request[\"datetime\"]),\n \"Recipient\" => $request[\"recipient\"],\n \"Sender\" => $request[\"sender\"],\n \"Body\" => $request[\"content\"]\n];\n\n?>", "language": "php" } ] } [/block] We log the date the Dynmark generated numeric message id, the date the message arrived, the phone number that the message was from, the Dynmark long number it was sent to and the body of the message. We now need to enable the sending of inbound messages to our new handler by visiting the Dynmark User Portal [Inbound Settings](https://apps.dynmark.com/DD/UserPortal/Home/IncomingForwarding) page and adding your inbound message handler endpoint to the Dynmark long number or keyword. [block:callout] { "type": "info", "title": "Note", "body": "The inbound message handler endpoint specified must be publicly accessible" } [/block] 3. Add a view page called InboundViewer.php which will allow us to view the messages we've received. [block:code] { "codes": [ { "code": "<table>\n <tr>\n <th>MessageId</th>\n <th>Date</th>\n <th>Sender</th>\n <th>Recipient</th>\n <th>Body</th>\n </tr>\n<?php \n session_start();\n\n parse_str($_SERVER[\"QUERY_STRING\"], $request);\n \n foreach ($_SESSION[\"InboundStore\"] as $inbound)\n {\n echo \"<tr>\";\n echo \"<td>\" . $inbound[\"MessageId\"] . \"</td>\";\n echo \"<td>\" . date_format($inbound[\"Date\"], 'Y-m-d H:i:s') . \"</td>\";\n echo \"<td>\" . htmlentities($inbound[\"Sender\"]) . \"</td>\";\n echo \"<td>\" . $inbound[\"Recipient\"] . \"</td>\";\n echo \"<td>\" . htmlentities($inbound[\"Body\"]) . \"</td>\";\n echo \"</tr>\"; \n }\n?>\n</table>", "language": "php" } ] } [/block]