【问题标题】:PHP Sending Form ScriptPHP 发送表单脚本
【发布时间】:2013-11-28 20:51:44
【问题描述】:

我在使 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 托管公司,即网络注册表。我试图打开 PHP 错误,但在我的 cpanel 中看不到。邮件未发送,但我无法看到阻止它的错误。

【问题讨论】:

  • 不工作怎么办?你有错误吗?邮件发不出去?怎么了?我们并不住在你的脑海里,也不知道你在想什么。
  • 您可以从您的服务器邮件服务器发送电子邮件吗?你在运行xampp吗?还是沼泽?如果是这样,默认情况下未配置电子邮件
  • 我更新了在 linux 托管服务器上运行的帖子。 @AmalMurali

标签: php forms email


【解决方案1】:

您的 html 中有错误。试试:

<form action="email.php"

【讨论】:

  • 谢谢,真是个愚蠢的错误。现在我注意到表单似乎正在发送,但转到空白页面 email.php,似乎仍然没有发送任何内容。
【解决方案2】:

将您的 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>

【讨论】:

  • 谢谢我意识到我忘记了等号,现在提交表单时,它只是进入 email.php 页面,没有任何内容发送到我的电子邮件
猜你喜欢
  • 1970-01-01
  • 2020-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多