Mass Email
In this short tutorial you will learn how to send a mass email to your website members.
Create a new file and call it: massmail.php
In this file you will want to code something like:
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
session_start(); //allow sessions
include("config.php"); //get database information
if($logged[username] && $logged[userlevel] != 6){ //check if logged in and admin
echo "You Are Not An Admin!"; //the person is not an admin
}elseif(!$logged[username]){ //check if logged in or not
echo "You Are Not Logged In"; //user not logged in
}else{ //said user is logged in and is an admin
if(!$_POST[send]){ //if the form was not submitted
echo "<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
<b>Subject</b>:
<input type=\"text\" name=\"title\" value=\"Untitled Message\" size=\"15\">
<b>Message</b>:
<textarea cols=\"58\" rows=\"10\" name=\"msg\"></textarea>
<input type=\"submit\" name=\"send\" value=\"Send Message\">
</form>"; //return with the form
}else{ //or if it was
$title = strip_tags(htmlspecialchars($_POST[title])); //title
$message = stripslashes($_POST[msg]); //message
$getusers = mysql_query("SELECT * FROM members"); //get all users
$headers = "From: NoReply@$_SERVER[SERVER_NAME]"; //who is it from?
if(empty($message)){
echo "<a href=\"history.go(-1)\">Go Back</a>You Can Not Send An Empty Message!";
}else{
while($r = mysql_fetch_array($getusers)){ //lets repeat for each email found
mail($r[email], $title, $message, $headers); //send mail to user
} //end while
echo "<a href=\"history.go(-1)\">Go Back</a>Email Sent!"; //success!
} //end check for empty message
} //end form check
} //end login and level check
?>
If you get any errors you can post a comment containing the error.