简体   繁体   English

无法从Html5 CSS和php表单获取信息

[英]Unable to get informations from a Html5 CSS and php form

I try to build a html5 form and send informations to form.php 我尝试建立一个html5表单并将信息发送到form.php

<h3>Contact Me</h3>
<p></p>
<form method="post" action="form.php">
    <div class="row uniform">
        <div class="6u 12u(xsmall)">
            <input type="text" name="name" id="name" placeholder="Name" />
        </div>
        <div class="6u 12u(xsmall)">
            <input type="email" name="email" id="email" placeholder="Email" />
        </div>
    </div>
    <div class="row uniform">
        <div class="12u">
            <input type="text" name="subject" id="subject" placeholder="Subject" />
        </div>
    </div>
    <div class="row uniform">
        <div class="12u">
            <textarea name="message" id="message" placeholder="Message" rows="6"></textarea>
        </div>
    </div>
    <div class="row uniform">
        <div class="12u">
            <ul class="actions">
                <li>
                    <input type="submit" class="special" value="Send Message" />
                </li>
                <li>
                    <input type="reset" value="Reset Form" />
                </li>
            </ul>
        </div>
    </div>
</form>

At the same place I have form.php 在同一地方,我有form.php

<?
if (isset($_POST['name']) && isset($_POST['email'])) {
    echo 'name '.$_POST['name'].' mail '.$_POST['email'];
}
?>

When I click on submit form.php page is open but blank. 当我单击form.php页面时打开,但是空白。

<?php
if (isset($_POST['name']) && isset($_POST['email'])) {
echo 'name '.$_POST['name'].' mail '.$_POST['email'];
}
?>

I think you missed the opening of PHP tag its <?php and not <? 我认为您错过了PHP标记的<?php而不是<? .

Yes sorry, now I can send by mail. 是的,抱歉,现在我可以通过邮件发送。

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: lespizz'; 
$to = 'jim@fdfrdsfg.com'; 
$subject = 'Hello';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
mail ($to, $subject, $body, $from)
?>

do you know how to get back on index.html automatically ? 您知道如何自动返回index.html吗?

Thanks 谢谢

Using PHP you may redirect to another page with this code : 使用PHP,您可以使用以下代码重定向到另一个页面:

header("Location: index.html");
die();

But beware - it will work only if there was no output before! 但是请注意-只有在之前没有输出的情况下,它才起作用!

Or if you have to give some output earlier you may just echo Javascript to redirect : 或者,如果您必须尽早提供一些输出,则可以只使用Javascript进行重定向:

echo '<script type="text/javascript">
           window.location = "http://www.google.com/"
      </script>';

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

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