Невозвратный sendmessage php. Отправка сообщений через API VK средствами PHP для ленивых

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!

Mixed CPosting::SendMessage( int ID,
int timeout = 0, int maxcount = 0,);

Нестатический метод отправляет выпуск в почтовую рассылку по адресам, указанным в таблице b_posting_email с соответствующим идентификатором выпуска. При этом обновляя статусы:

  • Y - еще не отправлялось
  • N - отправлено
  • Е - с ошибками
Выпуски со статусом "Успешно отправлен" повторно не отправляются. Если у выпуска установлен статус "Частично отправлен", то выпуск отправляется по оставшимся адресам.

Сначала выполняется попытка получения блокировки выпуска (см. CPosting::Lock). Если блокировку получить не удалось, то отправка считается частичной и возвращается "CONTINUE". Затем формируется тело письма для отправки и в цикле по адресам подписчиков осуществляется отправка выпуска с использованием функции bxmail .

В режиме отправки "Персонально каждому получателю" перед вызовом bxmail вызываются обработчики события BeforePostingSendMail.

В цикле отправки в очереди адресов делаются отметки об успешной отправке или ошибке.

С выпуска снимается блокировка(см. CPosting::UnLock).

Параметры Параметр Описание C версии
ID Идентификатор выпуска.
timeout Максимальное время отправки в секундах. При превышении этого времени прерывается работа и устанавливается статус выпуска "Частично отправлен". Параметр имеет значение только при методе отправки "Персонально каждому получателю". Если timeout=0, то отправка производится за один шаг. 3.2.0
maxcount Максимальное количество писем для отправки. При превышении этого количества прерывается работа и устанавливается статус выпуска "Частично отправлен". Параметр имеет значение только при методе отправки "Персонально каждому получателю". Если maxcount=0, то отправка производится за один шаг. 4.0.5
check_charset Сопоставлять текущую кодировку (константа LANG_CHARSET) с кодировкой в которой составлен выпуск или нет. Если кодировки не совпадают, то вернется "CONTINUE". Используется при отправке выпусков с помощью агентов. Сравнение выполняется без учета регистра кодировок. 8.0.1
Возвращаемые значения

Функция возвращает true при успешной отправке, false при неуспешной, "CONTINUE" при частичной отправке. При неуспешной отправке переменная LAST_ERROR класса содержит сообщение об ошибке.

См. также Пример использования