phpファイルの内容をHTMLで取得したい。HTMLメールテンプレートとして使用していますが、データベースから動的データを入力する必要があります。
私は試した
file_get_contents('/emails/orderconfirm.php');
しかし、それが行うのは、サーバーによってHTMLに処理される前にphpコードを返すことだけです。
本当に簡単だと思いますか?どんなアイデアでも大歓迎です。
ありがとう
で特定のコードを実行するには、そのコンテンツを含めるemails/orderconfirm.php
必要があります。
含まれるコンテンツはコンパイルおよびレンダリングされます。
ただし、あなたはあなたがいる限りコンテンツを取得する必要がありますecho
そのようにするには、 ob_start()ライブラリを使用する必要があります。
使用例は次のとおりです。
ob_start(); //Init the output buffering
include('emails/orderconfirm.php'); //Include (and compiles) the given file
$emailContent = ob_get_clean(); //Get the buffer and erase it
コンパイルされたコンテンツが$emailContent
変数に保存され、好きなように使用できます。
$email->body = $emailContent;
ob_start();
require 'emails/orderconfirm.php';
$email = ob_get_clean();
You are close, insert the complete URL
file_get_contents('http://example.com/emails/orderconfirm.php');
完全なhttpアドレスに移動してみてください。例:
file_get_contents('http://mydomain.com/emails/orderconfirm.php');