javascript - 在不更改 url 页面的情况下发送表单

标签 javascript php html forms

这是交易: 我设法通过创建 2 个重定向到索引的 html 页面来使这个 sendmail.php 工作。 但我想要的是 (if($sent) == true) 在 html 表单页面上显示消息已发送的警报。但是当我改变的时候

{echo "<script language=javascript>window.location = '/sent.html';</script>";}

{echo "<script language=javascript>window.alert = 'Message Sent';</script>";}

页面重定向到...url...com/sendmail.php 为空白

直播@www.aroundgalaxy.pt/NEW

这是表单html

<form action="sendmail.php" method="post">
    <div>
        <div class="row half">
            <div class="6u">
                <input type="text" class="text" name="name" placeholder="Nome" />
            </div>
            <div class="6u">
                <input type="text" class="text" name="email" placeholder="E-mail" />
            </div>
        </div>
        <div class="row half">
            <div class="12u">
                <input type="text" class="text" name="subject" placeholder="Assunto" />
            </div>
        </div>
        <div class="row half">
            <div class="12u">
                <textarea name="message" placeholder="Messagem"></textarea>
            </div>
        </div>
        <div class="row">
            <div class="12u">
                <input type="submit" class="button" value="Enviar" />
            </div>
        </div>
    </div>
</form>

和 sendmail.php

<?php
$to = "info@aroundgalaxy.pt";
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
//$site = $_REQUEST['site'] ;
$subject = "Message from: $name";
$message = $_REQUEST['message'] ;
$headers = "noreply@aroundgalaxy.pt";
$body = "From: $name \n\n Email: $email \n\n Message: $message";
$sent = mail($to, $subject, $body, $headers) ;
if($sent)
{echo "<script language=javascript>window.location = '/sent.html';</script>";}
else
{echo "<script language=javascript>window.location = '/notsent.html';</script>";}
?>

最佳答案

alert() 不是 alert =.

{echo "<script language=javascript>window.alert('Message Sent');</script>";}

关于javascript - 在不更改 url 页面的情况下发送表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20704570/

相关文章:

javascript - 当 div 显示时,JQuery 运行一个函数

javascript - jQuery 突出显示文本无法使用 .css ("background-color")

php - 带有签名 URL 的 Google Storage REST PUT

javascript - 从下拉菜单输出差异时获取空值? (Javascript)

html - Bootstrap 3 下拉菜单不显示

javascript - 函数的回调结果

javascript - 立即调用 IIFE 如何防止它污染全局范围?

php - 获取MySQL中两个日期相差的天数

php - HTTP PUT 请求 - 进度条实现

HTML/CSS 问题