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? Thank you all!
The form part from the 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
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.