php 建设中页面的非常简单的订阅表格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18370515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:25:04  来源:igfitidea点击:

Very simple subscribe form for under construction page

phpajaxemail

提问by Vasar

I'm setting up a Magento website and before it goes live I want to set up a under construction page.

我正在建立一个 Magento 网站,在它上线之前,我想建立一个正在建设中的页面。

I'd like to have people who are interested to subscribe and we'll send them out a email when the shop goes live.

我想让有兴趣的人订阅,我们会在商店上线时向他们发送电子邮件。

I tried out bunch of these bigger PHP mailing/newsletter systems, but they were way to complicated and time consuming to get into because I need to work on other things.

我尝试了一堆这些更大的 PHP 邮件/新闻通讯系统,但它们的方法既复杂又耗时,因为我需要处理其他事情。

So I'd like to know is there a easy way to do it myself or is there a script just for this task I haven't found yet? I also searched through few tutorial sites for what I was looking for, but I couldn't find anything useful. I really just need the bare minimum for this.

所以我想知道是否有一种简单的方法可以自己完成,或者是否有专门针对此任务的脚本我还没有找到?我还搜索了几个教程网站,寻找我想要的东西,但找不到任何有用的东西。我真的只需要最低限度的。

Thank you in advance, hopefully this question fits to this site.

预先感谢您,希望这个问题适合本网站。

采纳答案by UpAllNight

Make a simple form that lets users enter a name and email address. Have the email addresses go straight into a database or some other form of storage (could be as simple as a text file).

制作一个简单的表格,让用户输入姓名和电子邮件地址。让电子邮件地址直接进入数据库或某种其他形式的存储(可以像文本文件一样简单)。

Then, when ready, write a simple script that will send out an email to all the users in the database.

然后,准备好后,编写一个简单的脚本,该脚本将向数据库中的所有用户发送一封电子邮件。

回答by bogdA

use this in your page:

在您的页面中使用它:

<!-- Subscription Form -->
<form action="form/form.php" method="post">
    <input name="email" class="email" type="text" placeholder="Enter your email address ...">
    <button type="submit" class="btn_email">Send</button>
</form>
<!-- End Subscription Form -->

and this for form.php:

这对于form.php:

<?php
$to = "[email protected]";
$from = "[email protected]";

$headers = "From: " . $from . "\r\n";

$subject = "New subscription";
$body = "New user subscription: " . $_POST['email'];


if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) )
{ 
    if (mail($to, $subject, $body, $headers, "-f " . $from))
    {
        echo 'Your e-mail (' . $_POST['email'] . ') has been added to our mailing list!';
    }
    else
    {
       echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';   
    }
}
else
{
   echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';   
}

the above script will only send you an email with the new subscription, but you can extend it to do database insertion, subscriber confirmation, etc. And also validate the data in the field where the subscriber enter the email.

上述脚本只会向您发送一封带有新订阅的电子邮件,但您可以将其扩展为插入数据库、订阅者确认等。并且还验证订阅者输入电子邮件的字段中的数据。