Email link for multiple addressess?

Hi, - I have recently setup a simple database for a client - when they input data per person they have to include an email address.

Once all the data is in, the index page shows the persons name, and email address (there are 15 per page).

Is there a PHP code that can pick up all the email addresses on 1 page, so when you click it, it will open up all the email addresses in Outlook?

Or, is there a way you can have a 1 large text field, which displays all the email addresses using a PHP code?

Cheers,

Paul

Too vague to answer succinctly. Either concatenate your email addresses together with commas inbetween, or implode the emails over ‘,’…
and then a simple echo “<a href='mailto:”.$emails."'>Mass Email</a>

Each email address has to be individual to the persons data post - therefore means they cannot be linked together.

Was hoping there was a bit of code that might be able to either recognise an email address withinin a page, or something that can display all email addresses in a text field.

The Index page loops through each record.
Lets say that it retrieves the records as $row[‘name’] and $row[‘email’]

so your loop looks something like…


while($row = mysqli_fetch_array($result)) {
  echo "<tr><td>".$row['name']."</td><td>".$row['email']."</td></tr>";
}

So… if i stick this in…


while($row = mysqli_fetch_array($result)) {
  echo "<tr><td>".$row['name']."</td><td>".$row['email']."</td></tr>";
  $emails .= $row['email'].",";
}

Now $emails contains a comma-deliminated list of all emails you outputted to that page.

Ok, this sounds like it could work - but to be honest, I have no idea how to implement it doing it your way. Here is the HTML/ PHP I am using at the moment.

<?php foreach (get_posts($page) as $post) { ?>
				<tr>
					<td align="center" width="10&#37;" class="table_row"><input type="checkbox" name="delete<?php echo $post['post_id']; ?>" value="yes" /></td>
					<td width="30%" class="table_row"><?php echo $post['title']; ?></td>
					<td width="50%" class="table_row"><a href="mailto:<?php echo $post['email']; ?>"><?php echo $post['email']; ?></a></td>
					<td width="20%" class="table_row"><a href="/admin/database/posts/edit.php?post_id=<?php echo $post['post_id']; ?>" onclick="return popup('/admin/database/posts/edit.php?post_id=<?php echo $post['post_id']; ?>')"><img src="/admin/images/button_edit.gif" border="0" alt="Edit" /></a></td>
				</tr>
			<?php } ?>

Mmm. Duplication errors are ringing in my head, because that looks like a message board code.


<?php foreach (get_posts($page) as $post) { ?>
                <tr>
                    <td align="center" width="10&#37;" class="table_row"><input type="checkbox" name="delete<?php echo $post['post_id']; ?>" value="yes" /></td>
                    <td width="30%" class="table_row"><?php echo $post['title']; ?></td>
                    <td width="50%" class="table_row"><a href="mailto:<?php echo $post['email']; ?>"><?php echo $post['email']; ?></a></td>
                    <td width="20%" class="table_row"><a href="/admin/database/posts/edit.php?post_id=<?php echo $post['post_id']; ?>" onclick="return popup('/admin/database/posts/edit.php?post_id=<?php echo $post['post_id']; ?>')"><img src="/admin/images/button_edit.gif" border="0" alt="Edit" /></a></td>
                </tr>
            <?php
$emails[] = $post['email'];
 }
$emails = implode(",",array_unique($emails));
 ?>

Confused about the errors comment? - LOL

Once I implement that bit of code at the end, what is the next step to load all the email addresses on the current page in a mailto: link?

Cheers :slight_smile:

the errors comment was me saying that alarms started going off in my head that you’d be sending 1 person 10 emails because they posted 10 times on the thread. Basically i was telling myself (out loud. I do that a lot.) that i would have to use the array_unique call.


<?php
echo "<a href='mailto:".$emails."'>Mass Mail</a>";
?>

Ok, I think I’ve been a total numpty. - I actually have 2 files, for 1 page - the main code page which is index.php and then a template file, index.tpl.php.

Here is the index.php code:

<?php

define('ADMIN_ROOT_PATH', './../../');
require ADMIN_ROOT_PATH . 'includes/common.inc.php';

$tpl	= new template(ADMIN_ROOT_PATH . 'templates/');
$body	= new template(ADMIN_ROOT_PATH . 'templates/database/posts/');

$tpl->set('title', $config['site_name'] . ' - Admin Panel - Database - Posts');
$tpl->set('navigation', '<a href="/">Home</a> &raquo; <a href="/admin/">Admin Panel</a> &raquo; <a href="/admin/database/">Database</a> &raquo; Posts');

// Posts

if (!isset($_POST['submit'])) {
	/**
	* get_num_posts() - get the number of posts
	*
	* @return   integer, number of posts
	*/
	function get_num_posts() {
		$search_string = isset($_POST['search_string']) ? check_input($_POST['search_string']) : '';

		$result = $GLOBALS['db']->query("SELECT COUNT(p.post_id) FROM " . $GLOBALS['config']['db']['prefix'] . "database_posts p LEFT OUTER JOIN " . $GLOBALS['config']['db']['prefix'] . "categories c ON p.category_id = c.category_id WHERE p.title LIKE '&#37;$search_string%' OR p.age LIKE '%$search_string%' OR p.agegroup LIKE '%$search_string%' OR p.gender LIKE '%$search_string%' OR p.ethnic_id LIKE '%$search_string%' OR p.religion LIKE '%$search_string%' OR p.lifestage LIKE '%$search_string%' OR p.address_line1 LIKE '%$search_string%' OR p.address_line2 LIKE '%$search_string%' OR p.city LIKE '%$search_string%' OR p.county LIKE '%$search_string%' OR p.postcode LIKE '%$search_string%' OR p.occupation LIKE '%$search_string%' OR p.ocother LIKE '%$search_string%' OR p.jobtitle LIKE '%$search_string%' OR p.hoccupation LIKE '%$search_string%' OR p.hjobtitle LIKE '%$search_string%' OR p.hseg LIKE '%$search_string%' OR p.email LIKE '%$search_string%' OR p.phone LIKE '%$search_string%' OR p.mobile LIKE '%$search_string%' OR p.cage LIKE '%$search_string%' OR p.cage2 LIKE '%$search_string%' OR p.cage3 LIKE '%$search_string%' OR p.cage4 LIKE '%$search_string%' OR p.cage5 LIKE '%$search_string%' OR p.clifestage LIKE '%$search_string%' OR p.clifeother LIKE '%$search_string%' OR p.pets LIKE '%$search_string%' OR p.pets2 LIKE '%$search_string%' OR p.pets3 LIKE '%$search_string%' OR p.pets4 LIKE '%$search_string%' OR p.cmake LIKE '%$search_string%' OR p.cmake2 LIKE '%$search_string%' OR p.cmodel LIKE '%$search_string%' OR p.regyear LIKE '%$search_string%' OR p.ctype LIKE '%$search_string%' OR p.ctype2 LIKE '%$search_string%' OR p.mobprov LIKE '%$search_string%' OR p.mobprov2 LIKE '%$search_string%' OR p.internet LIKE '%$search_string%' OR p.internet2 LIKE '%$search_string%' OR p.gas LIKE '%$search_string%' OR p.gas2 LIKE '%$search_string%' OR p.electric LIKE '%$search_string%' OR p.electric2 LIKE '%$search_string%' OR p.landline LIKE '%$search_string%' OR p.landline2 LIKE '%$search_string%' OR p.tvprov LIKE '%$search_string%' OR p.tvprov2 LIKE '%$search_string%' OR p.pastres LIKE '%$search_string%' OR p.socialgrad LIKE '%$search_string%' OR p.reshistory LIKE '%$search_string%' OR p.reshistory2 LIKE '%$search_string%' OR p.findme LIKE '%$search_string%' OR p.findme2 LIKE '%$search_string%' OR p.content LIKE '%$search_string%' OR c.category_name LIKE '%$search_string%'");

		return $GLOBALS['db']->result($result, 0);
	}

	/**
	* get_posts() - get the posts
	*
	* @param    $page integer, current page
	* @return   array, posts
	*/
	function get_posts($page) {
		$search_string = isset($_POST['search_string']) ? check_input($_POST['search_string']) : '';

		$result = $GLOBALS['db']->query("SELECT p.*, c.category_name FROM " . $GLOBALS['config']['db']['prefix'] . "database_posts p LEFT OUTER JOIN " . $GLOBALS['config']['db']['prefix'] . "categories c ON p.category_id = c.category_id WHERE p.title LIKE '%$search_string%' OR p.age LIKE '%$search_string%' OR p.agegroup LIKE '%$search_string%' OR p.gender LIKE '%$search_string%' OR p.ethnic_id LIKE '%$search_string%' OR p.religion LIKE '%$search_string%' OR p.lifestage LIKE '%$search_string%' OR p.address_line1 LIKE '%$search_string%' OR p.address_line2 LIKE '%$search_string%' OR p.city LIKE '%$search_string%' OR p.county LIKE '%$search_string%' OR p.postcode LIKE '%$search_string%' OR p.occupation LIKE '%$search_string%' OR p.ocother LIKE '%$search_string%' OR p.jobtitle LIKE '%$search_string%' OR p.hoccupation LIKE '%$search_string%' OR p.hjobtitle LIKE '%$search_string%' OR p.hseg LIKE '%$search_string%' OR p.email LIKE '%$search_string%' OR p.phone LIKE '%$search_string%' OR p.mobile LIKE '%$search_string%' OR p.cage LIKE '%$search_string%' OR p.cage2 LIKE '%$search_string%' OR p.cage3 LIKE '%$search_string%' OR p.cage4 LIKE '%$search_string%' OR p.cage5 LIKE '%$search_string%' OR p.clifestage LIKE '%$search_string%' OR p.clifeother LIKE '%$search_string%' OR p.pets LIKE '%$search_string%' OR p.pets2 LIKE '%$search_string%' OR p.pets3 LIKE '%$search_string%' OR p.pets4 LIKE '%$search_string%' OR p.cmake LIKE '%$search_string%' OR p.cmake2 LIKE '%$search_string%' OR p.cmodel LIKE '%$search_string%' OR p.regyear LIKE '%$search_string%' OR p.ctype LIKE '%$search_string%' OR p.ctype2 LIKE '%$search_string%' OR p.mobprov LIKE '%$search_string%' OR p.mobprov2 LIKE '%$search_string%' OR p.internet LIKE '%$search_string%' OR p.internet2 LIKE '%$search_string%' OR p.gas LIKE '%$search_string%' OR p.gas2 LIKE '%$search_string%' OR p.electric LIKE '%$search_string%' OR p.electric2 LIKE '%$search_string%' OR p.landline LIKE '%$search_string%' OR p.landline2 LIKE '%$search_string%' OR p.tvprov LIKE '%$search_string%' OR p.tvprov2 LIKE '%$search_string%' OR p.pastres LIKE '%$search_string%' OR p.socialgrad LIKE '%$search_string%' OR p.reshistory LIKE '%$search_string%' OR p.reshistory2 LIKE '%$search_string%' OR p.findme LIKE '%$search_string%' OR p.findme2 LIKE '%$search_string%' OR p.content LIKE '%$search_string%' OR c.category_name LIKE '%$search_string%' ORDER BY title DESC LIMIT " . ($page - 1) * 15 . ", 15");

		return fetch_array($result);
	}

	$body->set('page', isset($_GET['page']) && is_numeric($_GET['page']) ? (int) $_GET['page'] : 1);
	$tpl->set('body', $body->fetch('index.tpl.php'));
} else {
	$result = $db->query("SELECT post_id FROM " . $config['db']['prefix'] . "database_posts");

	while ($post = $db->fetch_array($result)) {
		$status = isset($_POST['status' . $post['post_id']]) && $_POST['status' . $post['post_id']] == 0 ? 0 : 1;
		$delete = isset($_POST['delete' . $post['post_id']]) && $_POST['delete' . $post['post_id']] == 'yes' ? 'yes' : 'no';

		if (isset($_POST['status' . $post['post_id']])) {
			$db->query("UPDATE " . $config['db']['prefix'] . "database_posts SET status = $status WHERE post_id = $post[post_id]");
		}

		if ($delete == 'yes') {
			$db->query("DELETE FROM " . $config['db']['prefix'] . "database_posts WHERE post_id = $post[post_id]");
			$db->query("DELETE FROM " . $config['db']['prefix'] . "database_comments WHERE post_id = $post[post_id]");
		}
	}

	output('Posts successfully updated!');
	redirect('/admin/database/posts/', 2);
}

echo $tpl->fetch('layout.tpl.php');

?>

and here is the HTML/ PHP (bits) page…

<div style="position: absolute; top: 5px; right: 5px;"><?php echo "<a href='mailto:".$emails."'>Mass Mail</a>"; ?> - <a href="/admin/database/posts/new.php"><img src="/admin/images/button_new.gif" border="0" alt="New" /></a></div>
<form method="post" action="/admin/database/posts/">
	<p align="center" style="margin-top: 0;">Search <input type="text" name="search_string" value="<?php echo isset($_POST['search_string']) ? $_POST['search_string'] : ''; ?>" /> <input type="submit" name="search" value="Go" /></p>
</form>
<form method="post" action="/admin/database/posts/">
	<div class="table_box">
		<table border="0" cellpadding="3" cellspacing="1" width="100%">
			<tr>
				<td colspan="7" class="header"><h1>Posts</h1></td>
			</tr>
			<tr>
				<td width="10%" class="table_row"><strong>Delete:</strong></td>
			  	<td width="30%" class="table_row"><strong>Name:</strong></td>
				<td width="50%" class="table_row"><strong>Email:</strong></td>
				<td width="20%" class="table_row"></td>
			</tr>
			<?php foreach (get_posts($page) as $post) { ?>
				<tr>
					<td align="center" width="10%" class="table_row"><input type="checkbox" name="delete<?php echo $post['post_id']; ?>" value="yes" /></td>
					<td width="30%" class="table_row"><?php echo $post['title']; ?></td>
					<td width="50%" class="table_row"><a href="mailto:<?php echo $post['email']; ?>"><?php echo $post['email']; ?></a></td>
					<td width="20%" class="table_row"><a href="/admin/database/posts/edit.php?post_id=<?php echo $post['post_id']; ?>" onclick="return popup('/admin/database/posts/edit.php?post_id=<?php echo $post['post_id']; ?>')"><img src="/admin/images/button_edit.gif" border="0" alt="Edit" /></a></td>
				</tr>
			<?php } ?>
		</table>
</div>
	<?php echo multipage(get_num_posts(), 15, $page, '/admin/database/posts/index.php?page='); ?>
	<p align="center"><input type="submit" name="submit" value="Submit Changes" /></p>
</form>

You can see in the HTML code I have used the code…

<?php echo "<a href='mailto:".$emails."'>Mass Mail</a>"; ?>

I am guessing I need to include the

<?php $emails[] = $post['email']; } $emails = implode(",",array_unique($emails)); ?>

somewhere within the index.php page? - but I am also assuming it would be different as $post would not work.

Still no joy, any other tips for this? Cheers :slight_smile:

mmh nope… you should still put the emails bit where i put it in your template file.

Donedy done :slight_smile: … woop! Thanks for your help :slight_smile: