Electronic Post Office for Outbound Messages v1

scaiferw 0 Tallied Votes 115 Views Share

I wrote this code because I wanted the members of my volunteer organization go have a place they could easily get the most current list of email addresses to send a message.

This code reads the names and addresses from the database, and creates a comma delimited list of addresses in the format Smith, Janet <smithj@example.com>, .

It then creates two things:

1) A mailto: link to open a message window with all the addresses populated.

2) A <textarea> field that the list can be cut and pasted from.

I hope others find it useful. Comments and suggestions are welcome.

I post it here in recognition of the help I've received on this and other boards.

<!--~~~~~~ BUILD THE FORM FOR THE GENERAL MEMBERSHIP LIST ~~~~~~~~~~~~~~~~~~~~~~~~-->
// generate list of all names and email addresses for current members
$dataset_all = mysql_query("
SELECT id,firstname,lastname,email
FROM members 
WHERE status = 'current' 
ORDER BY lastname,firstname

// initialize this variable in which the list code will be built
$list 		= "";

// estimate # of rows needed for textearea
$addressrows  = (mysql_num_rows($dataset_all) / 2)+1;

// now loop through the records, cleaning up the data and building the list
while ($thisrow = mysql_fetch_array($dataset_all)) {

	// create a variable for each attribute
	foreach($thisrow as $var => $value){
		$$var = $value;

	// capture and clean data from this record
	$email	= trim($email);
	$name 	= "$firstname $lastname";

	// append this name/address to the list
	if ($thisrow["email"]) {
		$list .= " $name <$email>; ";

// a last bit of clean up on the list
$list  = trim($list);      // trim whitespace
$list  = rtrim($list,";"); // trim trailing semicolon
$list .= "\n";       // add a linefeed to facilitate cut and paste

// the list is now ready to be used in the form below.
<form name="form_current">
  <div style="border:1px solid tan;padding:10px;margin-bottom:15px;background-color:#fdf5e6;">
    <span style="color:maroon;font-weight:bold;">General Membership</span> (Contains primary eMail addresses of all current members.)
    <p><A href="mailto:<?php echo "$list"; ?>"><span style="font-weight:bold;border:1px solid tan;padding:0px 10px;margin-top:6px;background-color:#ffffff">Click here</span></a>
     to open a message form with the addresses filled in.  With some email programs, you will need to copy the address list from the box below.</p>
    <textarea id="holdtext" name="select1" cols="100" rows="<?php echo "$addressrows"; ?>" class="textarea" style="font-size:80%;font-weight:normal;padding:10px;">
      <?php echo "$list"; ?>