0

我有一个页面可以确定变量 ISSET,然后根据指令执行操作。例如,如果 isset 包含“打印”,它会通过包含模板路径加载文件并在底部回显打印窗口的代码。

例如。

if (isset($_GET['quoteprint'])) {
include(TEMPLATEPATH . '/bookings/booking-quote.php');
echo'<script type="text/javascript">window.print()</script>';
}

现在我希望存在一个类似的功能,但这次是将该页面的内容通过电子邮件发送给用户。我厌倦了这个,但它不起作用。我认为内容需要转换,但我不知道从哪里开始。

else if (isset($_GET['quoteemail'])) {
    $emailer = include(TEMPLATEPATH . '/bookings/booking-quote.php');
    $to = $current_user->user_email;
  $subject = "Your Quote - Dive The Gap" ;
  $message = $emailer;
  $headers = "From: Dive The Gap Bookings <ask@divethegap.com>" . "\r\n" .
             "Content-type: text/html" . "\r\n";

  mail($to, $subject, $message, $headers);
}

有任何想法吗?

奇妙

4

1 回答 1

1

include 函数不会返回您所包含的脚本的输出或内容。有关更多信息,请参见http://php.net/manual/en/function.include.php(示例 #4 可能对您来说很有趣)。

您需要将页面的全部内容或您要通过电子邮件发送的部分内容放入一个变量中。一种方法是使用 PHP 的输出缓冲。关于输出缓冲如何工作的一个很好的解释可以在这里找到:http: //www.codewalkers.com/c/a/Miscellaneous/PHP-Output-Buffering/

于 2011-03-02T13:20:10.700 回答