前提・実現したいこと
PHP上で多次元配列をメールとして送信したいです。
postfixのコンテンツフィルタにて、
PHPスクリプトを挟み込んで配送するメールのヘッダ(送信元)を書き換えたいと考えています。
受け取ったメールを多次元配列の形式に分解し、$structureに格納しています。
$params['include_bodies'] = true;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$params['input'] = $email;
$params['crlf'] = "\r\n";
$structure = Mail_mimeDecode::decode( $params );
[subject]の値を[from]の文頭に加えました。
var_dump($structure) をすると以下のような出力になります。
ヘッダ書き換え後メールの出力
object(stdClass)#2 (4) { ["headers"]=> array(9) { ["return-path"]=> string(25) "<user11@example.com>" ["x-original-to"]=> string(18) "user12@example.com" ["delivered-to"]=> string(18) "user12@example.com" ["received"]=> array(2) { [0]=> string(105) "by mail.example.com (Postfix, from userid 1008) id 7196D41A2D4; ------- +0900 (JST)" [1]=> string(163) "from example.com (localhost [127.0.0.1]) by mail.example.com (Postfix) with SMTP id AFF3241A2D3 for <user12@example.com>; ----------- +0900 (JST)" } ["from"]=> string(22) "test-user11@example.com" ["to"]=> string(18) "user12@example.com" ["subject"]=> string(4) "test" ["message-id"]=> string(49) "<20210518015754.AFF3241A2D3@mail.example.com>" ["date"]=> string(37) "-------- +0900 (JST)" } ["ctype_primary"]=> string(4) "text" ["ctype_secondary"]=> string(5) "plain" ["body"]=> string(6) "honbun " }
この$structureをsendmailコマンドにて配送しようと思います。
しかし、多次元配列だとsendmailができないです。
$structureをメール送信するにはどのような処理が必要でしょうか。
メール送信
/usr/sbin/sendmail -G -i $to_address < /var/spool/filter/[$structureの内容]
試したこと
元メールのオブジェクトがstringのため、配列形式をstringに変換するように試みました。
多次元配列かつ連想配列のため上手くいかず、var_exportを試しましたが、オブジェクト形式が不明になりました。
補足情報(FW/ツールのバージョンなど)
CentOS7
php-5.4.16
参考にさせていただいたページ
https://se.ykysd.com/2018/02/22/post-241/
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/06/15 00:07
2021/06/15 06:35