0

谁能给我详细说明如何在页面中编码?

基本上,我需要从头开始建立一个邮件列表,人们可以在其中订阅并将他们添加到邮件列表中。

它背后的 php/javascript 是什么?

4

2 回答 2

1

邮件列表非常简单。你需要决定你想怎么做,但一般来说,你会有一个订阅页面和一个帖子页面。我没有测试此代码,因此它可能包含缺陷,但它应该让您了解基于平面文件的邮件列表。

在实际实现中,你应该使用 MySQL,验证和确认电子邮件,检查错误等等。另外,不要忘记这不会验证帖子页面。理想情况下,您需要强大的身份验证来确保您的邮件列表不被泄露。另外要知道你必须有一个取消订阅功能——这对于 MySQL 来说比使用平面文件更容易。

订阅.php

<?php
// Has the form been posted?
if(isset($_POST['email']))
{
  // Append the submitted e-mail to the list.
  $file = fopen('list.txt', 'a');
  fputs($file, $_POST['email'] . "\n");
  fclose($file);

  // Send a message to the browser.
  die('Added to mailing list.');
}
?>
<html>
 <head>
  <title>Subscribe to Mailing List</title>
 </head>
 <body>
  <form action="#" method="post">
   <input type="text" name="email" />
   <input type="submit" value="Submit" />
  </form>
 </body>
</html>

post.php

<?php
// Has the form been submitted?
if(isset($_POST['body']))
{
  // This should load the file into $lines, as an array of, well, lines.
  $lines = file('list.txt');

  // For each line, send a message. $line should contain an e-mail address.
  foreach($lines as $line)
    mail($line, $_POST['subject'], $_POST['body']);

  // Send a message to the browser.
  die("Message delivered.");
}
?>
<html>
 <head>
  <title>Post to Mailing List</title>
 </head>
 <body>
  <h1>Post</h1>
  <form action="#" method="post">
   <input type="text" name="subject" /><br/>
   <textarea name="body"></textarea><br/>
   <input type="submit" value="Submit" />
  </form>
 </body>
</html>
于 2011-02-10T05:09:44.420 回答
0

实际上,它背后还有更多——更多的 MySQL。您需要 MySQL、PHP 和 Javascript(用于 UI 和客户端验证)

你想从哪里开始?

简单模型: 用户 -> 输入电子邮件 -> 通过 javascript 验证 -> if (true) -> 通过 POST/GET 提交 -> 验证 PHP -> if (true) -> 进入 MySQL 数据库。

于 2011-02-10T05:02:57.597 回答