addemail.php
<!DOCTYPE html>
<html lang="cn" dir="ltr">
<head>
<meta charset="UTF-8">
<title>猫王商店 - 添加邮箱</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<img src="blankface.jpg" width="161" height="350" alt="" style="float:right">
<img name="elvislogo" src="elvislogo.gif" width="229" height="32" border="0" alt="Make Me Elvis">
<p>E添加你的名字和邮箱到 <strong>猫王商店</strong> 的邮箱列表。</p>
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$output_form = 'no';
if (empty($name) || empty($email)) {
echo '请完整填写要求的内容.<br />';
$output_form = 'yes';
}
}
else {
$output_form = 'yes';
}
if(!empty($name)&&!empty($email)){
$dbc = mysqli_connect('127.0.0.1','root','','elvis_store')
or die('链接MySQL失败。');
$query = "INSERT INTO email_list (name, email)".
"VALUES ('$name', '$email')";
mysqli_query($dbc, $query)
or die('数据添加失败。');
echo '顾客信息添加完成。';
mysqli_close($dbc);
}
if ($output_form == 'yes'){
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<label for="NAME">姓名:</label>
<input type="text" name="name" id="name"><br>
<label for="email">邮箱地址:</label>
<input type="text" name="email" id="name"><br>
<input type="submit" name="submit" value="提交">
</form>
<?php
}
?>
</body>
</html>
sendemail.php
<!DOCTYPE html>
<html lang="cn" dir="ltr">
<head>
<meta charset="utf-8">
<title>猫王商店 - 发送邮件</title>
<<link rel="stylesheet" href="style.css">
</head>
<body>
<img src="blankface.jpg" alt="黑脸" width="161" height="350" style="float:right">
<img src="elvislogo.gif" alt="猫王商店" name="elvislogo" width="229" height="32" border="0">
<p><strong>私人的:</strong>仅供Elmer使用<br>
向邮箱列表的成员写和发送邮件。</p>
<?php
if (isset($_POST['submit'])) {
$from = 'xxxxxxxx@xxx.com';
$subject = $_POST['subject'];
$text = $_POST['elvismail'];
$output_form = false;
if (empty($subject) && empty($text)) {
// We know both $subject AND $text are blank
echo '你忘记输入邮件的标题和内容。<br>';
$output_form = true;
}
if (empty($subject) && (!empty($text))) {
echo '你忘记输入邮件标题<br>';
$output_form = true;
}
if ((!empty($subject)) && empty($text)) {
echo '你忘记输入邮件正文.<br>';
$output_form = true;
}
}
else {
$output_form = true;
}
if ((!empty($subject)) && (!empty($text))) {
$dbc = mysqli_connect('127.0.0.1','root','','elvis_store')
or die('链接MySQL失败。');
$query = "SELECT * FROM email_list";
$result = mysqli_query($dbc, $query)
or die('查询数据库失败。');
while($row = mysqli_fetch_array($result)){
$name = $row['name'];
$msg = "亲爱的 $name ,\n $text";
$to = $row['email'];
mail($to, $subject, $msg, 'From:'.$from);
echo '邮件发送到了:'.$to.'<br>';
}
mysqli_close($dbc);
}
if ($output_form) {
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<label for="subject">邮件的标题:</label><br>
<input type="text" name="subject" id="subject" size="30"><br>
<label for="elvismail">邮件的内容:</label><br>
<textarea name="elvismail" id="elvismail" rows="8" cols="40"></textarea><br>
<input type="submit" name="Submit" value="提交">
</form>
<?php
}
?>
</body>
</html>
removeemail.php
<!DOCTYPE html>
<html lang="cn" dir="ltr">
<head>
<meta charset="utf-8">
<title>猫王商店 - 删除邮箱</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<img src="blankface.jpg" alt="黑脸" width="161" height="350" style="float:right">
<img src="elvislogo.gif" alt="猫王logo" width="229" height="32" name="elvislogo" border="0">
<p>输入你想要移除的邮箱。</p>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
$dbc = mysqli_connect('127.0.0.1','root','','elvis_store')
or die('链接MySQL失败。');
if(isset($_POST['submit'])){
foreach ($_POST['todelete'] as $$delete) {
$query = "DELETE FROM email_list WHERE id = $delete_id0";
mysqli_query($dbc, $query)
or die('查询数据库失败。');
}
echo "顾客邮箱移除完毕。<br>";
}
$query = "SELECT * FROM email_list";
$result = mysqli_query($dbc, $query)
or die('查询数据库失败。');
while($row = mysqli_fetch_array($result)){
echo '<input type="checkbox" value="' .$row['id']. '" name="todelete[]">';
echo "$row['name']";
echo "$row['email']";
echo "<br>";
}
mysqli_close($dbc);
?>
<input type="submit" name="submit" value="Remove" />
</form>
</body>
</html>