Possible Duplicate:
Problem when loading php file into variable (Load result of php code instead of the code as a string)
I am bit confused about following...
message alert function
public static function MsgAlert($email, $name, $subject, $message)
{
$msg = include('mailer.php');
$subject = 'New Message';
if ($email != '' && validate_email($email))
{
$mailer = new PHPMailer();
$mailer->SetFrom(ADMIN_EMAIL, SITE_NAME);
$mailer->AddAddress($email);
$mailer->Subject = $subject;
$mailer->Body = Postman::nl2br($msg);
$mailer->AltBody = $msg;
$mailer->Send();
}
}
I have put my newsletter design into mailer.php, and please check markup for that...
mailer.php
<div>
<h1><?php $subject; ?><span>27 September 2011 at 6:26 pm</span></h1>
<div>
<p>Hello <?php $name; ?>,</p>
<?php $message; ?>
</div> <!--message container -->
</div>
Am i using correct approach or should i do something more better as its not working. please suggest. thanks.
You cannot include to a variable, but what you can do is use php's output buffering functions to achieve the desired outcome, e.g.:
ob_start();
include 'mailer.php';
$msg = ob_get_clean();
This will render the template and store the result in $msg.
include() does not RETURN whatever you're including. It'll return true for success (file was included/executed) or false (file couldn't be included). With your current structure, you're need this:
ob_start();
include('mailer.php');
$msg = ob_get_clean();
to capture the output of the mailer.php script as it's included.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With