Hi,
I hope you know how to send a mail to a user in php. If you know this, then the below code can help you.
Basic idea: Show a checkbox in front of every email id. Select and click a submit button to send emails to the selected email ids.
<?
if($_POST['submit'] == "Send Mass Mail")
{
// When someone presses submit button given below
if(count($_POST['email_ids']) >0)
{
foreach($_POST['email_ids'] as $key)
{
//mail function - (to_field, subject_field,msg_field,headers)
// Set it accordingly
$subject = "Your mailer subject";
$to = $key;
$msg = "Here is our product";
mail($to,$subject,$msg,$header);
}
}
}
?>
// This is the form that shows all the emails and the checkboxes
<form name="emailfrm" method="post" action="">
<table border="0" cellpadding="2" cellspacing="1">
<thead>
<tr>
<th>Email Id</th>
<th> </th>
</tr>
</thead>
<tbody>
<?php
$res = mysql_query("Select email from <tablename>");
while($data = mysql_fetch_array($res))
{
// Show all the emails from the database. Choose the tablename above
?>
<tr>
<td><?php echo $data['email']; ?></td>
<td><input type="checkbox" name="email_ids" id="email_ids" value="<?php echo $data['email']; ?>" /></td>
</tr>
<?php
}
?>
<tr>
<td colspan="2"><input type="submit" name="submit" id="submit" value="Send Mass Mail" />
</tr>
</tbody>
</table>
</form>
Reputation Points: 11
Solved Threads: 12
Junior Poster in Training
Offline 94 posts
since Dec 2008