功能在动态电子邮件中运行

时间:2014-09-22 18:01:26

标签: php dynamic styling

我正在尝试使用PHP在确认电子邮件中动态显示一行。

    //E-mail Alert Formatting
        $submission = date('D M d g:i a');

        $originalDate = $DateNeededInHand;
        $newDate = date("Y-m-d", strtotime($originalDate));

        $now = time(); // or your date as well
        $due_date = strtotime($newDate);
        $datediff = abs($now - $due_date);
        $urgency = round(((($datediff / 60) / 60) /24),0,PHP_ROUND_HALF_DOWN);

    //Not Working
        function urgent($urgency) {
            if ($urgency <= 2) {
                echo '<div style="font-weight:bold; color:red;">URGENT!</div>';
            }
        }

------------------ ^ In PHP document ^ v In HTML document v ------------------

    <p><b>Submission: </b>'.$submission.'&nbsp;&nbsp;'.urgent($urgency).'</p>

它没有显示动态位。

1 个答案:

答案 0 :(得分:0)

你不能把PHP放在一个HTML文档中。你可以把HTML放在一个PHP文件中。所以首先你的底部代码块需要在一个php文件中。那么你的代码需要看起来像这样:

<p><b>Submission: </b><?php echo $submission.'&nbsp;&nbsp;'.urgent($urgency); ?></p>