简体   繁体   English

当按下提交页面重新加载为 php 文件

[英]when press submit the page reloading as the php file

I have some problem with my form... When I press the submit button the page not only doesn't send the mail, it also reloading the page and show the php file at a text all over the website... Someone know how to fix that please?我的表单有一些问题......当我按下提交按钮时,页面不仅不发送邮件,它还重新加载页面并在整个网站的文本中显示 php 文件......有人知道如何请解决这个问题? Thank you all!谢谢你们!

The form part from the HTML: HTML 中的表单部分:

<form action="mail.php" method="post">
                <table class="table">
                    <tbody>
                        <tr>
                            <td rowspan="2" width="50%">
                                <div class="cart-total">
                                    <strong class="cart-total-title">סך הכל</strong>
                                    <span class="cart-total-price">0₪</span>
                                </div>
                            </td>
                            <td align="right" width="25%">
                                <input type="text" name="inpPhone" size="10" required></input>
                                :טלפון
                            </td>
                            <td align="right" width="25%">
                                <input type="text" name="inpName" size="10" required></input>
                                :שם מלא
                            </td>
                        </tr>
                        <tr>
                            <td align="right" width="25%">
                                <input type="text" name="inpCity" size="10" required></input>
                                :עיר
                            </td>
                            <td align="right" width="25%">
                                <input type="text" name="inpAddress" size="10" required></input>
                                :כתובת
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3" align="right">
                                <input type="date" name="inpDate" required></input>
                                :תאריך אספקה (ניתן להזמין עד יומיים לפני)
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3" align="right">
                                </br>
                                אם הוזמנו מארז עוגיות/עוגת שמרים, יווצר עמך קשר בהמשך לגבי בחירת עוגיות/עוגה *
                            </td>
                        </tr>
                    </tbody>
                </table>
                <input type="submit" class="btn btn-primary btn-purchase" name="submit">להזמנה</button>
            </form>

PHP: PHP:

<?php

if (isset(_POST['submit'])) {
    $subject = "הזמנה חדשה";
    $name = $_POST['inpName'];
    $phone = $_POST['inpPhone'];
    $city = $_POST['inpCity'];
    $address = $_POST['inpAddress'];

    $mailTo = "sappati@outlook.com";
    $headers = "From:".$name;
    $txt =
        "התקבלה הזמנה חדשה! אלו פרטי ההזמנה:\n".
        "שם: ".$name."\n".
        "טלפון: ".$phone."\n".
        "עיר: ".$city."\n".
        "כתובת: ".$address."\n";

    mail($mailTo, $subject, $txt, $headers);
}

?>

It's the native behavior of server side languages to reload to handle the request, if you want to make requests to server side, then you should use XMLHttpRequest or fetch or any other library for making requests重新加载来处理请求是服务器端语言的本机行为,如果你想向服务器端发出请求,那么你应该使用XMLHttpRequestfetch或任何其他库来发出请求

And about the php file being served as text, you should have apache or any other server install on your local machine to be able to handle server side code关于作为文本的 php 文件,您应该在本地机器上安装 apache 或任何其他服务器,以便能够处理服务器端代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM