L
L
lynnikvadim2016-07-17 13:56:50
PHP
lynnikvadim, 2016-07-17 13:56:50

Unable to parse mail?

Where is the mistake?
I do as it is written here https://habrahabr.ru/post/126448/
My file is /etc/aliases :

# /etc/aliases
mailer-daemon: postmaster
postmaster: root
nobody: root
hostmaster: root
usenet: root
news: root
webmaster: root
www: root
ftp: root
abuse: root
noc: root
security: root
root: test
mail: "|php -q /home/mail.php"

mailbox [email protected]*****.ru
Mail comes and goes to this box.
code /home/mail.php
<?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); ?>

Debian server+roundcube+ispconfig
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2016-07-17
@Rsa97

Actually, if mail arrives at this address, then your line in aliases does not work, otherwise all mail to this address would go to the script. Did you run the newaliases command?

V
Vladimir Dubrovin, 2016-07-17
@z3apa3a

A single quote is missing in the string with mail(). Check manually that the script is started and fulfilled.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question