PHP发送表单脚本

时间:2013-11-28 12:45:03

标签: php forms email

我在使用PHP脚本时遇到了一些麻烦。我正在制作一个非常基本的表格,只收集姓名和电子邮件

<form action"email.php" method="POST" id="signup-form">
                    <p><input type="text" id="name" name="name" placeholder="name" /></p>
                    <p><input type="email" id="email" name="email" placeholder="email address" /></p>
                    <p class="form-note"><em>* we will only email you when our store is up</em></p>
                    <p><input type="submit" value="Get Notified" /></p>
                </form>

我的PHP脚本是

<?php
    $error = false;
    $sent = false;

    if(isset($_POST['submit'])) {
        if(empty($_POST['name']) || empty($_POST['email'])) {
            $error = true;
        } 
        else {

            $to = "my.name@gmail.com";

            $name = trim($_POST['name']);
            $email = trim($_POST['email']);

            $subject = "New Subscriber";

            $message =  "Name: $name \r\n Email: $email";
            $headers = "From:" . $name;
            $mailsent = mail($to, $subject, $message, $headers);

            if($mailsent) {
                $sent = true;
            }
       }
  }
?>

我正在使用Linux托管公司,net注册表。我试图打开PHP错误,但无法看到我的cpanel中的错误。邮件没有发送,但我无法看到阻止它的错误。

2 个答案:

答案 0 :(得分:3)

你的html中有错误。尝试:

<form action="email.php"

答案 1 :(得分:1)

将您的HTML更改为此并尝试

<form action="email.php" method="POST" id="signup-form">
                    <p><input type="text" id="name" name="name" placeholder="name" /></p>
                    <p><input type="email" id="email" name="email" placeholder="email address" /></p>
                    <p class="form-note"><em>* we will only email you when our store is up</em></p>
                    <p><input type="submit" value="Get Notified" /></p>
                </form>