Click to See Complete Forum and Search --> : Send emails to record owners


Davidbw
01-15-2005, 04:08 PM
I use a Perl front end (Webdata Pro) for a mysql database of excavators' listings of dirt fill. The front end has limitations and cannot do this: I want to have an email sent (nightly cron) to record owners 10 days before the expiration of the record. I'd like to include a link to the record in the email that is sent. The records reside in the table 'findamatch', and the field 'expiration' is a date field. The auto-increment key field is 'id_1'. The record owner's email address is in "email'. I am a novice. I've gone through a few tutorials and read several posts and am reading a book, but this is way over my head. I would like to learn how to do this. Any help would be greatly appreciated. I have pieced together the start of a script.

<?php
$hostname = "localhost";
$db_name = "dbname";
$db_user = "dbuser";
$db_pass = "dbpassword";
$message = "Your record will expire in 10 days. To change the expiration date, go here: "
$nenewurl = "http://database.com/cgi-bin/find.pl?_cgifunction=Search&TableName=findamatch&_layout=modify&keyval="
$keyval = "id_1"
$from = "administrator@database.com"
$subject = "Listing Expiration"

mysql_connect ($hostname, $db_user, $db_pass);
mysql_select_db ($db_name);

$result = mysql_query ("SELECT * FROM findamatch" WHERE expiration = CURRENT_DATE - 10");

Now here is where I would like to extract the email address 'email' and record ID 'id_1' from each found record and use those values to send emails with a link to the record. Thanks in advance for any help.

96turnerri
01-15-2005, 07:01 PM
try adding something like

while($row = mysql_fetch_assoc($result)) {
echo "Email: ".$row["email"]."<br>";
echo "ID_1: ".$row["ID_1"]."<br>";
}

after all the code you posted

Davidbw
01-16-2005, 12:37 PM
Thanks! That works, and I continue to be amazed at the power of php. Now I've been wrestling with arrays and "foreach" in particular, and while I get some of it conceptually, implementation eludes me:
------------
$result = mysql_query ("SELECT * FROM findamatch WHERE expiration = CURRENT_DATE + 10");
while($row = mysql_fetch_assoc($result)) {
$addresses = $row['emailaddress'];
$ids = $row['id_1'];
foreach ($addresses as $value {
print $value;
}
}
?>
-------------
can't even get that to work, and I need to get each email address WITH the accompanying "id_1" in order to send the emails. This is probably too complicated to go through this on the forum. I'll just find someone and pay to get it done.

96turnerri
01-16-2005, 01:54 PM
try making it


foreach ($addresses as $key => $val) {
print $val."<br>";
}