Forum Moderators: coopster

Message Too Old, No Replies

Email php form address list array

         

tiranto

2:44 am on Mar 25, 2011 (gmt 0)

10+ Year Member



I got a email address list loaded from a MYSQL Database which loads a list of users with a check box next to their name, which I manually tick and press send mail, and it Echoes out the values but i want it to load a mailto with the email addresses in the "to" box.

I’ve got this far but can’t seem to work it, tied loading a mail to and echoing in HTML but only loaded one of the email address not all of them using something crude like (<a href="mailto:<?php echo($toemail[$i] . "; ");>); ?>">List to email</a>)

Hope it all makes sense its simple I’m sure but then I’m not getting it, I’m also wanting to add a "check all" box at the bottom, its in the code but not got the Java to do it, I had it working but when loaded the name eadd[] for the array the check all stopped working

See below source code for reference any help will be greatly appreciated.

-----------------------
Source Code - Index.php
-----------------------
<?php

$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="users"; // Database name
$tbl_name="user"; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

?>
<html>
<link href="../../../style.css" rel="stylesheet" type="text/css">

</head>
</body>
<center>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="25"><b>&nbsp;</b></td>
<td width="50"><b>ID</b></td>
<td width="100"><b>Surname</b></td>
<td width="100"><b>First Name</b></td>
<td width="200"><b>Email</b></td>
<td width="200"><b>Group</b></td>
</tr>

<?php ////////////////////////////////////////////////// ?>
<?php $query = "SELECT * FROM $tbl_name WHERE sys_list='yes' ORDER BY s_name";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){ ?>

<center>
<form name="myform" method="post" ACTION="post.php">
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="25"><center>
<input type="checkbox" name="eadd[]" title="Select (<?php echo $row['f_name']; ?> <?php echo $row['s_name']; ?>)"
value="<?php echo $row['email']; ?>"></td>
<td width="50"><?php echo $row['ID']; ?></td>
<td width="100"><?php echo $row['s_name']; ?></td>
<td width="100"><?php echo $row['f_name']; ?></td>
<td width="200"><a href="mailto:<?php echo $row['email']; ?>"><?php echo $row['email']; ?></a></td>
<td width="200"><?php echo $row['list_group']; ?></td>
</tr>
<?php } ?>
<?php //////////////////////////////////////////////////// ?>
<tr>
<td colspan="1"><center>
<input type='checkbox'></td>
<td colspan="2">Select All</b></td>
<td colspan="2"><p align="right"><input type="submit" value="Send Email"></p></td>
</tr>
</table>
</form>


---------------------------------------------------
Source Code - post.php
-----------------------
<?php
$toemail = $_POST['eadd'];
if(empty($toemail))
{
echo("You didn't select any contacts.");
}
else
{
$N = count($toemail);

echo("Email to be sent to $N contacts: ");
for($i=0; $i < $N; $i++)
{
echo($toemail[$i] . "; ");
}
}
?>
---------------------------------------------------

coopster

1:07 am on Apr 2, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Are you trying to create a mailer script based off a database table? Are you having trouble with the JavaScript?

tiranto

11:06 pm on Apr 3, 2011 (gmt 0)

10+ Year Member



Hey Coopster, Thanks for your response.

The main code, Genorates a address book, which has Email add, name and a tick box, down the bottom there is a send mail button, the post.php Arays the data and outputs all the email address's ticked which is good, but i want it to do a mail to, and add the aray results into the "To" section of the mailto form. Iv tried echoing my self, but it will only load 1 out of the 2,3,10,100 names i select but if i use the simple php echo above it lists's all the names as it shold. When the mailto is setup, the echo on screen will be removed and it will load a new blank email on screen only when you select send email.

Thats the bit im having difficulty with, thanks.

coopster

7:28 pm on Apr 4, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



OK, missed the whole "mailto" on the first look here. This is going to be unreliable. I would advise using a server side email handler rather than mailto for multiple recipients. Further reading:
[webmasterworld.com...]