在动态电子邮件中运行的函数


Function running in an dynamic e-mail

我正在尝试使用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>

它没有显示动态位。

您不能将php放在html文档中。您可以将html放在php文档中。因此,首先,您的底层代码块需要位于php文件中。那么你的代码需要看起来像这样:

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