我只是想知道我们能否在PHP Mail中包含用户定义的函数
$to = "example@example.com";
$message = '<html>';
$message .='</html>';
$from = "webmaster@example.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$headers .= "From:" . $from;
我尝试了上面的代码,我只是得到了消息&#39;&lt; / html&gt;&#39;(没有引号)在我的邮件中。并且该功能被打印在屏幕上。我不希望在屏幕上打印该功能,我想要运行该功能并将内容邮寄给用户。 BTW该函数是从MYSQL数据库动态生成的HTML表。我在互联网上搜索过但无法找到任何具体的答案。
答案 0 :(得分:0)
有可能是你的displayWinesList()
函数echo是它的数据,而不是返回它。
您可以修改函数以返回数据或保持原样并使用输出缓冲来捕获数据:
$to = "example@example.com";
$subject = "WineStore Query";
ob_start();
displayWinesList($connection, $query,$region_name, $wine_type, $price);
$message = ob_get_clean();
$message = '<html>'.$message.'</html>';
$from = "webmaster@example.com";
…
要确定无疑,请发布您的displayWinesList()
功能。