首页 > 解决方案 > php滚动到页面底部后,div中的消息没有被执行

问题描述

我在 PHP 中有一个联系表。发送邮件后,我想要滚动到页面底部的功能,以便用户可以查看邮件是否已发送。如果邮件已发送/发送失败,我们会使用 div 的警报类收到错误消息。但是,在页面滚动到底部后,我无法看到警报框,但是如果我删除滚动到底部功能,即使在邮件发送后我也能够看到警报消息。谁能指导我哪里错了。

<?php
//validation done here
 if(mail($toEmail, $subject, $body, $headers)){
                    // Email Sent
                    $msg = 'Your email has been sent';
                    $msgClass = 'alert-success';

                } else {
                    // Failed
                    $msg = 'Your email was not sent';
                    $msgClass = 'alert-danger';

                }
                header('Location:index.php#bottomOfPage');
?>


 //remaining html goes here 
    <?php if($msg != ''): ?>

        <div class="alert <?php echo $msgClass; ?>"><?php echo $msg; ?></div>

    <?php endif; ?>
    <a name="bottomOfPage"></a>
    //form is here

标签: phphtml

解决方案


Please move the 'bottomOfPage' name tag above the success/failure message displaying
Try the code like below

<a name="bottomOfPage"></a>
<?php if($msg != ''): ?>

        <div class="alert <?php echo $msgClass; ?>"><?php echo $msg; ?></div>

    <?php endif; ?>

推荐阅读