DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Michael has posted 27 posts at DZone. View Full User Profile

Mass Email

02.13.2007
| 219 views |
  • submit to reddit
        // send email out to list of email addresses in a db

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<?php
include './inc/config.inc.php';
?>

<?
if (isset($_POST['submit']))
{

	$subject = $_POST['subject'];
	$message = $_POST['message'];

	
	$query="SELECT email FROM users_test";  //Change users_test to users
	$result=mysql_query($query);
	$num=mysql_num_rows($result);


	$i=0;
	while ($i < $num) 
	{
	
		$email=mysql_result($result,$i,"email");
			
		mail($email, $subject, $message, "From: Someone<someone@somewhere.com>\nX-Mailer: PHP/" . phpversion());
	
		echo "Email sent to: " . $email . "<br />";
	
		$i++;
				
	}
}
?>
<br />

		
<form name="email" action="<?=$_SERVER['email.php']?>" method="post">

Subject
<br />
<input name="subject" type="text" size="50" id="subject"><br /><br />
Message
<br />
<textarea name="message" cols="50" rows="10" id="message"></textarea>
<br /><br />
<input type="submit" name="submit" value="Email!">
        
</body>
</html>