基本的に、PHP と互換性のある独自の sendmail スタイルのラッパーを作成する必要があります。PHP がsendmail
メール送信を呼び出すと、プロセスが開かれ、メッセージ データが sendmail に書き込まれます。
メッセージを送信するには、メッセージを再解析する必要があります。または、メッセージをログに記録/アカウント化した後、そのまま MTA に転送する必要があります。
オプションをサポートしないサンプル スクリプトを次に示しますが、このルートに進みたい場合は開始する必要があります。
#!/usr/bin/php -q
<?php
// you will likely need to handle additional arguments such as "-f"
$args = $_SERVER['argv'];
// open a read handle to php's standard input (where the message will be written to)
$fp = fopen('php://stdin', 'rb');
// open a temp file to write the contents of the message to for example purposes
$mail = fopen('/tmp/mailin.txt', 'w+b');
// while there is message data from PHP, write to our mail file
while (!feof($fp)) {
fwrite($mail, fgets($fp, 4096));
}
// close handles
fclose($fp);
fclose($mail);
// return 0 to indicate acceptance of the message (not necessarily delivery)
return 0;
このスクリプトは実行可能にする必要があるため、権限を に設定し755
ます。
php.ini
次に、このスクリプトを指すように編集します (例: sendmail_path = "/opt/php/php-sendmail.php -t -s"
)
別のスクリプトで、メッセージを sendmail してみます。
<?php
$ret = mail('drew@example.com', 'A test message', "<b>Hello User!</b><br /><br />This is a test email.<br /><br />Regards, The team.", "Content-Type: text/html; charset=UTF-8\r\nX-Mailer: MailerX", '-fme@example.com');
var_dump($ret); // (bool)true
それを呼び出した後、の内容に/tmp/mailin.txt
は次のようなものが含まれている必要があります。
To: drew@example.com
Subject: A test message
X-PHP-Originating-Script: 1000:test3.php
Content-Type: text/html; charset=UTF-8
X-Mailer: MailerX
<b>Hello User!</b><br /><br />This is a test email.<br /><br />Regards, The team.
上記の txt ファイルの内容は基本的に、再送信できるように解析する必要があるか、使用する MTA に直接渡すことができる可能性があります。この例の引数については何もしていないので、忘れないでください。
man sendmail
そのプロセスに関する詳細なドキュメントを 参照してください。のディレクティブにメールを書き込む PHP の関数へのリンクを次に示します。sendmail_path
php.ini
mail()
それが役立つことを願っています。