addemail.phpphp
<!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.phpcss
<!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.phphtml
<!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>