nieuwsbrief
Auteur: pj_muller00 - 08 oktober 2006 - 16:15 - Gekeurd door: Wijnand - Hits: 52875 - Aantal punten: 2.38 (4 stemmen)
Na dat iemand vroeg in samenwerken om voor hem een nieuwsbrief script te schrijven heb ik dat maar even gedaan.
En dan kan ik het even goed ook via deze weg aan anderen geven ...
|
Code: |
config pagina :
<?php
$tabel = 'tabel';
$header = "From: Yourname <info@yourname.com>";
?>
<?php $tabel = 'tabel'; $header = "From: Yourname <info@yourname.com>"; ?>
insert pagina ...
<?php
include_once('config.php');
if(isset($_POST['insert'])){
$query = "INSERT INTO ".$tabel." (email) VALUES ('".$_POST['email']."')";
mysql_query($query);
echo $_POST['email']." inserted<br>";
}
else{
?>
<form method="post">
<table>
<tr>
<td>New email-adres</td>
<td><input type="text" name="email" size="25" maxlength=45></td>
<td><input type="submit" name="insert" value="Insert !"></td>
</tr>
</table>
</form>
<?php
}
?>
<?php include_once('config.php'); if(isset($_POST['insert'])){ $query = "INSERT INTO ".$tabel." (email) VALUES ('".$_POST['email']."')"; echo $_POST['email']." inserted<br>"; } else{ ?> <form method="post"> <table> <tr> <td>New email-adres</td> <td><input type="text" name="email" size="25" maxlength=45></td> <td><input type="submit" name="insert" value="Insert !"></td> </tr> </table> </form> <?php } ?>
Admin kant deleten, verwijderen:
<?php
include_once('config.php');
if(isset($_POST['delete'])){
$query = "SELECT id,email FROM $table";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
if(isset($_POST['email'.$row['id']])){
$query = "DELETE FROM $table WHERE id = ".$row['id'];
mysql_query($query);
echo $row['email']." deleted<br>";
}
}
}
else{
?>
<form method="post">
<table>
<?php
$query = "SELECT id,email FROM $table";
$result = mysql_query($query);
while($row = mysql_fetch_array($result){
echo "
<tr>
<td>".$row['email']."</td>
<td><input type='checkbox' name='email".$row['id']."'></td>
</tr>";
}
?>
</table>
<input type="submit" name="delete" value="Delete">
</form>
<?php
}
?>
<?php include_once('config.php'); if(isset($_POST['delete'])){ $query = "SELECT id,email FROM $table"; if(isset($_POST['email'.$row['id']])){ $query = "DELETE FROM $table WHERE id = ".$row['id']; echo $row['email']." deleted<br>"; } } } else{ ?> <form method="post"> <table> <?php $query = "SELECT id,email FROM $table"; <tr> <td>".$row['email']."</td> <td><input type='checkbox' name='email".$row['id']."'></td> </tr>"; } ?> </table> <input type="submit" name="delete" value="Delete"> </form> <?php } ?>
Mail versturen :
<?php
include_once('config.php');
if(isset($_POST['send'])){
echo "<h2>Send</h2><br>";
$title = stripslashes($_POST['title']);
$message = stripslashes($_POST['message']);
echo "<b>".$title."</b><br>";
echo nl2br($message)."<br>";
$query = "SELECT distinct email FROM ".$table;
$result = mysql_query($query);
while($row = mysql_fetch_array($resultaat)){
$email = mail($row['email'],$title,$message,$header);
if($email == 1){
echo "Mail sended ".$row['email']."<br>\n";
}
elseif($email == 0){
echo "Not sended to".$row['email']." <br>\n";
}
}
}
elseif(isset($_POST['example'])){
echo "<h2>Example</h2><br>";
$title = stripslashes($_POST['title']);
$message = stripslashes($_POST['message']);
echo "<b>".$title."</b><br>";
echo nl2br($message)."<br>";
?>
<form method="post">
<input type="hidden" name="message" value=<?= $message; ?>">
<input type="hidden" name="title" value="<?= $title; ?>">
<input type="submit" name="send" value="Send ">
</form>
<?php
}
else{
echo "<h2>Mailing</h2><br>";
?>
<form method="post">
Title : <input type="text" name="title" size=50><br>
Message : <br><textarea name="message" cols=50 rows=4 wrap=virtual></textarea><br><br>
<input type="submit" name="example" value="Show example">
</form>
<?php
}
?>
<?php include_once('config.php'); if(isset($_POST['send'])){ echo "<h2>Send</h2><br>"; echo "<b>".$title."</b><br>"; $query = "SELECT distinct email FROM ".$table; $email = mail($row['email'],$title,$message,$header); if($email == 1){ echo "Mail sended ".$row['email']."<br>\n"; } elseif($email == 0){ echo "Not sended to".$row['email']." <br>\n"; } } } elseif(isset($_POST['example'])){ echo "<h2>Example</h2><br>"; echo "<b>".$title."</b><br>"; ?> <form method="post"> <input type="hidden" name="message" value=<?= $message; ?>"> <input type="hidden" name="title" value="<?= $title; ?>"> <input type="submit" name="send" value="Send "> </form> <?php } else{ echo "<h2>Mailing</h2><br>"; ?> <form method="post"> Title : <input type="text" name="title" size=50><br> Message : <br><textarea name="message" cols=50 rows=4 wrap=virtual></textarea><br><br> <input type="submit" name="example" value="Show example"> </form> <?php } ?>
Download code (.txt)
|
|
Stemmen |
Niet ingelogd. |
|