반송 된 이메일을 PHP 스크립트로 전달하여 처리하도록합니다. 나는 사용하고있다.TO 필드를 수집하는 PHP 스크립트가 포함 된 전자 메일 배관?
#!/usr/bin/php -q
<?php
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
// handle email
$lines = explode("\n", $email);
// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;
for ($i=0; $i < count($lines); $i++) {
if ($splittingheaders) {
// this is a header
$headers .= $lines[$i]."\n";
// look out for special headers
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
} else {
// not a header, but message
$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
// empty line, header section has ended
$splittingheaders = false;
}
}
?>
완벽하게 작동합니다! 그러나 반송 된 메시지의 "받는 사람"필드는 어떻게 수집합니까? 변수에 $를 추가하려고 시도했지만 작동하지 않습니다.
어떤 도움이 좋을 것,
덕분에,
편집 : 사실은 내가 메시지 본문 내에서 "TO"필드를 얻을 필요가있다. - 다시 반송 된 이메일. 특정 정보를 얻기 위해 메시지 본문을 어떻게 분리합니까? 이 정보를 얻는 것이 더 쉽도록 그 사람의 이메일과 함께 특별한 헤더를 만들어야합니까?
메시지의 본문이 어떻게 보이는지 알아야 정규식으로 그 메시지를 가져올 수 있습니다. – Alasdair
때로는 더 신뢰할 수있는 또 다른 옵션은 고유 한 리턴 경로로 모든 메시지를 보내는 것입니다. 그렇게하면 메시지가 반송되는 이메일 주소를 기반으로 어떤 메시지가 다시 수신되는지 알 수 있습니다. –