创建联系表单

use*_*208 -2 html php contact contact-form

我对PHP编码知之甚少.我有这个联系表格:

http://jsfiddle.net/HtU4D/

<div id="content">
   <h1> Contact me </h1>

    <form action=" " method="post"  autocomplete="on">
        <p> <label for="username" class="iconic user" > Name <span class="required">*</span></label> <input type="text" name="username" id="username"  required="required" placeholder="Hi friend, how may I call you ?"  /> </p>

        <p> <label for="usermail" class="iconic mail-alt"> E-mail address <span class="required">*</span></label> <input type="email" name="usermail" id="usermail" placeholder="I promise I hate spam as much as you do" required="required"  /> </p>

        <p> <label for="usersite" class="iconic link"> Website </label> <input type="url" name="usersite" id="usersite"  placeholder="eg: http://www.miste.com" /> </p>

        <p> <label for="subject" class="iconic quote-alt"> Subject </label> <input type="text" name="subject" id="subject"  placeholder="What would you like to talk about?" /> </p>

        <p> <label for="message" class="iconic comment"> Message  <span class="required">*</span></label> <textarea placeholder="Don't be shy, live me a friendly message and I'll answer as soon as possible "  required="required" ></textarea> </p>
        <p class="indication"> All fields with a <span class="required">*</span> are required</p>

        <input type="submit" value=" ?  Send the mail !" />     

    </form>     
</div> 
Run Code Online (Sandbox Code Playgroud)

我想要"发送邮件!" 按钮将详细信息直接发送到我的电子邮箱.

我应该制作什么文件?联系表单文件已经是PHP文件,但我不知道要添加什么!

抱歉我的英语不好,如果你不理解我的问题,请告诉我!

Jon*_*t92 5

创建一个像mail.php这样的PHP文件.在表单中,您将指向该文件.

<form action="mail.php" method="post">
Run Code Online (Sandbox Code Playgroud)

在mail.php中,您将验证输入:

$username = isset($_POST["username"]) ? $_POST["username"] : "";
Run Code Online (Sandbox Code Playgroud)

这意味着如果实际设置了username,那么$username将获得该值,否则为空字符串.

使用三元运算符.您应该为所有输入执行此操作.

如果您不想使用三元运算符(我强烈推荐),那么您可以这样做:

if(isset($_POST["username"]))
{
    $username = $_POST["username"];
}
else
{
    $username = "";
}
Run Code Online (Sandbox Code Playgroud)

如果您对所有输入都满意,那么您可以使用内置邮件功能发送电子邮件.

完成后,您可以重定向用户:

header("Location: index.php");
Run Code Online (Sandbox Code Playgroud)

我已经回答了一个类似的问题,您可以随时查看,互联网上还有大量的资源可以帮助您.