【问题标题】:Mailing list subscription [closed]邮件列表订阅[关闭]
【发布时间】:2020-02-06 01:37:43
【问题描述】:

我的网站上有这个部分,号召性用语是:

“订阅我的邮件列表,以便在我的完整网站时收到通知 发布。”

我如何收集电子邮件地址并将它们保存到文件中(我猜它需要某种 php 或其他服务器端语言)

HTML 代码如下

<div class="right">
                <p class='attention'>Website to be released <br>early-mid 2020!</p>
                <form action="mailto" method="post" enctype="text/plain">
                <input type="text" name='email' id='email' placeholder="your email">
                <button type="submit">Notify Me</button>
            </form>
            </div>

【问题讨论】:

    标签: php html forms email


    【解决方案1】:

    这非常具体到您的要求,它将帮助您将电子邮件 ID 保存到项目目录中的文件“data.txt”中。

    <!DOCTYPE html>
    <html>
    <head>
    <title>Store form data in .txt file</title>
    </head>
    <body>
        <div class="right">
            <p class='attention'>Website to be released <br>early-mid 2020!</p>
            <form method="post">
                <input type="text" name='email' id='email' placeholder="your email">
                <button type="submit" name="submit">Notify Me</button>
            </form>
        </div>
    </body>
    </html>
    <?php
    
    if(isset($_POST['submit']))
    {
    $data=$_POST['email']. PHP_EOL;
    $fp = fopen('data.txt', 'a');
    fwrite($fp, $data);
    fclose($fp);
    }
    ?>
    

    【讨论】:

    • 我应该把php放在哪里?
    • 以上代码 sn-p 可以放在一个文件中,EX : 'index.php'。
    • 那么它是如何工作的呢?我已将 php sn-p 放入 index.php 中,将 html 放入 index.html 文件中,填写表格什么也没做?
    • 不,你需要把html和php都放在'index.php'文件中,然后打开页面,希望你有一个web服务器在运行,如果没有,请检查如何安装XAMPP Apache 或打开 IIS。但是,如果您是初学者,我建议您使用 XAMPP,因为它可以帮助您将 php、DB 和 wed 服务器作为一个包安装。
    猜你喜欢
    • 1970-01-01
    • 2010-12-20
    • 2014-08-10
    • 2013-08-10
    • 2022-10-24
    • 2019-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多