Безбрежный sendmessage php. Отправка сообщений через API VK средствами PHP для ленивых. HTTP запросами, передавая через POST параметры отправляем сообщения или используем любые другие методы API

Kids these days, I tell ya. All they care about is the technology. The video games. The bottled water. Oh, and the texting, always the texting. Back in my day, all we had was...OK, I had all of these things too. But I still don"t get the volume of texts that I hear my younger female cousins send. Thousands and thousands of them each month. WTF are all of these texts for? Here"s a thought:

omg i can"t believe you didn"t hear

jenny and mark were holding hands

ok i made it up, ur so lame

Riveting. Jokes aside, text messaging can be an extremely useful way to get out of calling that person you hate calling communicate quickly and efficiently. Many websites are now offering text message notifications instead of email notifications, which can be nice in the case of time-sensitive information. After a bit of research, I found out how easy it was so send text messages using PHP, so that I can integrate text messaging into my apps! Let me show you how!

The Methodology

Unbeknownst to me, sending text messages can be as easy as sendmail, because you can send your text to an email address and it will be delivered. There are two pieces of information you must know: the phone number and the carrier"s text message email domain. Needing to know the recipient"s carrier is not ideal, but necessary. Luckily Kevin Jensen has compiled a list of carriers and domains :

Phone companies have internal lookups for phone carriers but developers like you and I don"t get access to them, so knowing the carrier is a must. To send a text message, you email {phoneNumber}@{carrierDomain} .

The PHP

PHP"s provided method for sending emails is the mail function . Its usage is quite simple:

Bool mail (string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]])

Using the mail function and the text message email format, sending a text message is as easy as:

// Call Jenny mail("[email protected]", "", "Your packaged has arrived!", "From: David Walsh \r\n");

Note that no subject line is provided, and more importantly, a FROM header is within the last parameter so that the recipient knows where the text message has been sent from.

Who knew it was that easy? I always assumed text messaging had its own protocol and all that magic. Apparently not! Spend a few minutes playing around with text messaging yourself; it"s one of those things that"s both neat to do and useful!

Что мы будем делать: настроим отправку сообщений от имени конкретного пользователя в несколько чатов и другим пользователям используя HTTP запрос средствами PHP , с минимальными усилиями.

Собственно, одними сообщениями мы не ограничимся. Все будет работать через standalone приложение vk по тому принципу, что мы потенциально сможем делать все действия, которые будут доступны этому самому пользователю (точнее все то, на что мы выдадим сами себе права, но об этом чуть позже).

Сообщения рассматриваем именно по той причине, что с ними можно работать только в standalone-приложениях.

План действий:
1. Создаем приложение
2. Получаем access_token
3. отправляем сообщения
1. Создаем приложениеЭтот пункт делать под тем аккаунтом, к которому будет привязано приложение (Не обязательно тот же, с которого будут идти сообщения).

Имя пишем какое угодно - фигурировать оно нигде не будет.
Тип - Standalone-приложение.

Больше тут можно ничего не трогать.

2. Используя ID и secret_key из приложения получаем access_tokenaccess_token - строка из некоторого количества символов, которая будет отправляться с POST запросом для выполнения каких то функций. Собственно, к ней привязано, от имени какого пользователя будем действовать и что нам можно будет делать.

Для этого создаем на сайте страничку вот с таким кодом: