PHP Code:
<?
require_once('connect.php');
$query = "SELECT user_emails FROM tbl_users ORDER BY users_date desc";
$result = @mysql_query ($query) or die ("failed : ".mysql_error());
$num = mysql_num_rows ($result) or die ("failed : ".mysql_error());
if ($num > 0) {
echo "
There are currently $num user(s) to email to.</p>";
if(isset($_POST['mail_form'])) {
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
if($row['0'] && $subject && $message) {
mail($row['0'], $subject, $message);
}
}
}
}
mysql_free_result ($result);
} else {
echo '
There are no people to send news to, your site sucks.</p>';
}
mysql_close();
?>
<form name="mail" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="subject" />
<input type="text" name="message" />
<input type="submit" name="mail_form" value="Mail that news!" />
</form>
I just wrote this out and don't have time or the effort to test it, so ifyou find a few minor bugs just change them, only common sense is needed, just remember to set your classes and include your header and footer tags.
and to register them something like this might work:
PHP Code:
<?php
if(isset($_POST['register'])) {
if ($usr_mail) {
require_once('connect.php');
$query = "INSERT INTO tbl_users (user_emails) VALUES ('$usr_mail')";
$result = @mysql_query ($query);
if ($result) {
$message = '
You are now on our mailing list, mate.</p>';
} else {
$message = '
You could not be registered for one reason or another, try again later.</p>';
}
}
?>
<form name="register" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="usr_mail" />
<input type="submit" name="register" value="Sign up!">
</form>
once again there may be a few minor bugs, but you don't needmasses of knowledge to edit them out
There is also a very easy way with PEAR, but if you wanna know how to use that you'll have to goto
PEAR's Website