In fact, you need to deploy a mail service (for example, Postfix), and process the mail included in it via a php script. This article describes such a scheme.
- First, make sure you have a working mail server.
You can make a separate mailer in the subdomain, just make 2 entries in the DNS:
rob.mydomain.ru. A ip-вашего-сервера rob.mydomain.ru. MX rob.mydomain.ru.
- Edit the file with aliases
/etc/aliases : add a line there: robot: "|php -q /путь/к/скрипту.php" robot is the name of the mailbox; /путь/к/скрипту.php - script processing incoming.
after editing, run the newaliases command
- In the
postfix main.cf settings, I recommend adding a parameter: recipient_delimiter = +
then it will be possible to encode additional information in the address: robot+someId@rob.mydomain.ru
All letters to such addresses will also process our script. someId can be a user id or any other data.
- create a script-processor of letters:
<?php /** * Скрипт для автоматической обработки входящих писем * * Все данные smtp-конверта письма RECIPIENT, SENDER и другие postfix * передает через окружение $_ENV; полный перечень переменных: * http://www.postfix.org/local.8.html секция EXTERNAL COMMAND DELIVERY */ //текст сообщения считываем из STDIN $msg = file_get_contents("php://stdin"); //отправитель письма $sender = getenv('SENDER'); //получатель письма $recipient = getenv('RECIPIENT'); //парсинг сообщения list($header, $body) = explode("\n\n", $msg, 2); //выделим строки с Subject: и From: $subject = ''; $from = ''; $headerArr = explode("\n", $header); foreach ($headerArr as $str) { if (strpos($str, 'Subject:') === 0) { $subject = $str; } if (strpos($str, 'From:') === 0) { $from = $str; } } //для отладки сохраняем полученное сообщение в лог: $logMsg = "=== MSG ===\n"; $logMsg .= "SENDER: $sender\n"; $logMsg .= "RECIPIENT: $recipient\n"; $logMsg .= "$from\n"; $logMsg .= "$subject\n\n"; $logMsg .= "$msg\n"; file_put_contents('/tmp/inb.log',$logMsg, FILE_APPEND);
From A. Gorlova's sathya: https://habrahabr.ru/en/post/126448/
myrobot@gmail.com, then you can do somyrobot+jhgjhuUUhfnjfj75858ndjdbash53544@gmail.com. PS Spammers in this way from one address can register and spam a bunch of accounts :) - Visman