Forum Moderators: coopster
That way, when the email is sent, the message body consists of the executed php code from another file.
<?php
mail("$email", "$subject", "require_once('email2.php');",
?>
The above code is obviously not right. Can anyone suggest anything?
Thanks.
I've written a small piece of code to get
the contents of file text.php.
Contents of text.php are:
--------------------------
<?
$a="XYZ";
$b="ABC";
for($i=0;$i<5;$i++)
{
echo $a.$b;
}
?>
File parsing the above code:
----------------------------
<?
$code = implode ('', file ('text.php'));
ob_start(); //turn output buffering on
eval(str_replace("?>","",str_replace("<?","",$code)));
$message=ob_get_contents();
ob_end_clean(); //turn off output buffering
mail("to@xyz.com","the subject",$message,"From:me@xyz.com";
?>
Personally I feel this is a complex way of doing things.
Better way would be to build your message variable inside
the file "xyz.php" and use the variable after the
include "xyz.php" statement directly.
<?php
mail($email, $subject, require('email2.php'));
?>
if you made sure that email2.php does not use any output functions but returns the text you want to use as your email using the return() [php.net] construct.
Alternatively you could do something like crypto describes: Start a new output buffer with ob_start() [php.net], do your require() [php.net] (there is no need to eval() [php.net]ue the code, [url=http://www.php.net/require]require() [php.net][/url] or [url=http://www.php.net/include]include() [php.net][/url] will work just fine) and then get the output of the require() [php.net] by calling ob_get_contents() [php.net]. To stop this output buffer call ob_end_clean() [php.net].
Andreas