hydrazi
Posts: 12
|
| Posted: 02/14/2011, 11:10 AM |
|
Hello,
I want to be able to send an email alert about an insert to a certain table. I want it to send to each email address listed in another table.
I know how to send the insert alert. It works fine for my email address, hard-coded.
How do I create a $email_to that lists all the emails in a table?
_________________
Matt Rand |
 |
 |
JayEdgar
Posts: 77
|
| Posted: 02/15/2011, 6:45 AM |
|
Run a query of the table that has the email addresses.
|
 |
 |
hydrazi
Posts: 12
|
| Posted: 02/15/2011, 7:26 AM |
|
Where do I put the code? I tried this from another post:
function GetAddresses() {
// Create a datasource on the fly, and read the "to" info
$db = new clsDBInternetDB();
$SQL = "SELECT Emailaddress FROM Emails"; // ** Change to match your database **
$db->query($SQL);
$to = "";
$sep = ""; // separator between addresses
if ($db->next_record())
{
do
{
$to = $to . $sep . $db->f("Emailaddress"); // ** Change the field name to match your database **
if (!$sep) {
$sep = ", "; // Subsequent addresses get separated by a comma
}
} while ($db->next_record());
}
return $to;
} // end of function.
It errors telling me that clsDBInternetDB() is not a recognized class. Any ideas?
_________________
Matt Rand |
 |
 |
Waspman
Posts: 948
|
| Posted: 02/15/2011, 8:35 AM |
|
this is straight out of my registration page...
global $eb_regnotify;
global $db_regnotify;
$db_regnotify = new clsDBConnection1();
$SQL = "SELECT firstname, lastname, email FROM tb_users WHERE RecievesEmails = 1";
$db_regnotify->query($SQL);
while ($db_regnotify->next_record()) {
$eb_regnotify = "Hi,".$db_regnotify->f("firstname");
$eb_regnotify = $eb_regnotify."The following student has registered<br><br><br>";
$eb_regnotify = $eb_regnotify."Name: ".$Container->firstname->GetValue()." ".$Container->lastname->GetValue()."<br><br><br>";
$eb_regnotify = $eb_regnotify."Go to the administration area for more details<br><br>";
$to = $db_regnotify->f("email");
$subject = "Registration Notification";
$message = $eb_regnotify;
$from = $Sender;
$charset = "Windows-1252";
$transferEncoding = "";
$additional_headers = "From: $from\nReply-To: $from\nContent-Type: text/html; charset=$charset\nContent-Transfer-Encoding: $transferEncoding";
mail ($to, $subject, $message, $additional_headers);
}
$db_regnotify->close();
_________________
http://www.waspmedia.co.uk |
 |
 |
datadoit
|
| Posted: 02/15/2011, 8:56 AM |
|
Reference the connection object first:
global InternetDB;
|
|
|
 |
hydrazi
Posts: 12
|
| Posted: 02/20/2011, 10:33 AM |
|
Awesome! That did it! Many thanks! Now I learned how to do similar things too!!!
_________________
Matt Rand |
 |
 |
|