0

I need to make email notification for my service Written in php. So the question is: Is it correct to use ob_start() and ob_get_clean() or there is a better way?

Simple Example:

<?php

...class logics...

ob_start();
include 'email_html_tpl.php';
$msg = ob_get_clean();
Email::Send('example@example.com', $msg);

?>

Notice that all this happens in script called via ajax.

Maxim Pavlov
  • 195
  • 1
  • 1
  • 10

1 Answers1

2

I am assuming you want to inject variables and/or do some light processing in your email template to generate the actual content.

In that context, it's perfectly fine if you are OK with your email templates being given the power to execute arbitrary code -- this is not an uncommon technique.

Jon
  • 428,835
  • 81
  • 738
  • 806
  • Thx, for your answer, it seems to me i found a solution by parsing placeholders! – Maxim Pavlov May 23 '14 at 20:41
  • @user2750845: That's another common technique. But if all the templates are going to be authored by trusted people, you might want to consider what you stand to gain by replacing placeholders instead. – Jon May 23 '14 at 20:43