Jump to content

Email annonce


feri_soft

Recommended Posts

How to create something like a newslater but where users define their limitations and whenever a new item is added the script  searches throught the limitations table and email each user which limitations match these of the added item :)


For example a user submits to be emailed whenever an item with cat asd is added and any other value of 200. I want when a new item is added the script to search throught the users records which are saved in a table and find these which match the added item and email those users ;)
Link to comment
https://forums.phpfreaks.com/topic/27890-email-annonce/
Share on other sites

Asuming there's a "notify" table where rows are inserted whenever a customer chooses the option of being notified when a particular item is added/available...with the a field that has the item's id in it....
[code]
<?php

  $db->query("INSERT INTO items (sku, title, price) VALUES ('$addnew[sku]','$addnew[title]','$addnew[price]')");

  $query = "SELECT * FROM notify WHERE itemid = '$addnew[itemid]'";
  $customers = $db->query($query);

  while($ncustomers = $db->fetch_row($customers)) {

  mail (YOUR EMAIL CRITERIA HERE);

  $db->query("DELETE FROM notify WHERE itemid = '$addnew[itemid]'");

  }

?>[/code]

Or something similar. Example is just to show a possible approach.
Link to comment
https://forums.phpfreaks.com/topic/27890-email-annonce/#findComment-127577
Share on other sites

yes thats ok,but the problem is that i dont have the new item id but a long where cluase with possible options like between x and x .... > x etc....and i need first ti verify for which of the users requierments the new item is fine then select the users id and send them the mail ;)
Link to comment
https://forums.phpfreaks.com/topic/27890-email-annonce/#findComment-128040
Share on other sites

I found this in one application which is very simillar to what i want to do but i dont know the "-" use of substr and some other things. Can you show a different approach to do the same or explain the code please:

[code=php]
<?php
function notify_new_listing($listingID)
{
global $conn, $lang, $config;
$display = '';
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
require_once($config['basepath'] . '/include/search.inc.php');
$sql = "SELECT userdb_id, usersavedsearches_title, usersavedsearches_query_string, usersavedsearches_notify FROM " . $config['table_prefix'] . "usersavedsearches WHERE usersavedsearches_notify = 'yes'";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
while (!$recordSet->EOF) {
$query_string = $misc->make_db_unsafe($recordSet->fields['usersavedsearches_query_string']);
$user_id = $recordSet->fields['userdb_id'];
$search_title = $misc->make_db_unsafe($recordSet->fields['usersavedsearches_title']);
// Break Quesry String up into $_GET variables.
unset($_GET);
$query_string = urldecode($query_string);
$criteria = explode('&', $query_string);
foreach ($criteria as $crit) {
if ($crit != '') {
$pieces = explode('=', $crit);
$pos = strpos($pieces[0], '[]');
if ($pos !== false) {
$name = substr($pieces[0], 0, -2);
$_GET[$name][] = $pieces[1];
}else {
$_GET[$pieces[0]] = $pieces[1];
}
}
}
if (!isset($_GET)) {
$_GET[] = '';
}
$matched_listing_ids = search_page::search_results(true);
if (in_array($listingID, $matched_listing_ids)) {
// Listing Matches Search
$sql = "SELECT userdb_user_name, userdb_emailaddress FROM " . $config['table_prefix'] . "userdb WHERE userdb_id = " . $user_id;
$recordSet2 = $conn->Execute($sql);
if ($recordSet2 === false) {
$misc->log_error($sql);
}
$email = $misc->make_db_unsafe($recordSet2->fields['userdb_emailaddress']);
$user_name = $misc->make_db_unsafe($recordSet2->fields['userdb_user_name']);
$message = $lang['automated_email'] . "\r\n\r\n\r\n" . date("F j, Y, g:i:s a") . "\r\n\r\n" . $lang['new_listing_notify_long'] . "'" . $search_title . "'.\r\n\r\n" . $lang['click_on_link_to_view_listing'] . "\r\n\r\n$config[baseurl]/index.php?action=listingview&amp;listingID=" . $listingID . "\r\n\r\n\r\n" . $lang['automated_email'] . "\r\n";
// Send Mail
$sent = $misc->send_email($config['admin_name'], $config['admin_email'], $email, $message, $lang['new_listing_notify']);
$display .= $lang['new_listing_email_sent'] . $user_name . "': " . $lang['new_listing_notify'] . "'" . $search_title . "'<br>";
}
$recordSet->MoveNext();
} // while
return $display;
}

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/27890-email-annonce/#findComment-128648
Share on other sites

  • 5 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.