Page 1 of 1
Email after inser does not work
Posted: 2013-12-15 15:37
by RonP
Hi,
In the former version I've edited in the contacten.php hooks file to send an email after each inserted record.
I've read in this forum that something migth have changed, however adjusting the given code to my table (contacten) results in a white screen.
Do I miss something? (The only changes where table name and e-mail.
I've inserted the complete function
Code: Select all
function contacten_insert(){
// mm: save record change data
$recID=mysql_insert_id();
sql("insert into membership_userrecords set tableName='contacten', pkValue='$recID',
memberID=' ".getLoggedMemberID()."', dateAdded=' ".time()."', dateUpdated='".time()." ',
groupID=' ".getLoggedGroupID().".", $eo);
@mail(
/*comma-separated listed of recipients */
"[email protected]",
/*message subject */
"Database change to the Contacten table notification",
/*message contents */
"A new record has been added by: ".getLoggedMemberID().
".\n\n".
"To view it, please go to: \n"
"http://oursite.com/appginidatabasefilefolder/routes_view.php?SelectedID=$redID",
/*sender email */
"From: [email protected]"
);
return (get_magic_quotes_gpc() ? stripslashes($recID) : $recID);
}
function contacten_before_insert(&$data, $memberInfo, &$args){
/* verhoog lidaatschapsnummer automatisch met 1 */
/* $data['LidNR'] = 1 + (1 - $data['LidNR']; */
return TRUE;
}
Re: Email after inser does not work
Posted: 2014-01-02 19:22
by a.gneady
Hmm ... the name of the first function should be contacten_after_insert() rather than contacten_insert() ... There are some parameters passed to it as well that are removed in your code ... the correct definition line should read:
Code: Select all
function contacten_after_insert($data, $memberInfo, &$args){
Re: Email after inser does not work
Posted: 2014-01-04 11:29
by RonP
Hello a.gneady,
Thank you for the correction.
I've overlooked the statement AND it seemed that I had 2 RETURN statements in the function, one to many, that was why there came no mail.
All works fine now.
Ron
Re: Email after inser does not work
Posted: 2014-03-04 19:09
by toconnell
Ahmad,
I am trying this too.. here is my code. .. no syntax errors in dreamweaver but when I change a record it is not sending emails.. ran several tests and nothing.. Your thoughts?
Thanks,
Code: Select all
function routes_after_insert($data, $memberInfo, &$args){
// to compose a message containing the submitted data when changes are done to routes table,
// we need to iterate through the $data array
foreach($data as $field => $value){
$messageData .= "$field: $value \n";
}
$recID=mysql_insert_id();
sql("insert into membership_userrecords set tableName='routes' , pkValue='#recID',
memberID=' ".getLoggedMemberID()."', dateAdded=' ".time()."', dateUpdated='".time()."',
groupID= ".getLoggedGroupID().".", $eo);
@mail(
// mail recipient
"[email protected], [email protected], [email protected], [email protected]",
// subject
"A Record in the Routes table of the database was changed - notification",
// message
"The following new record was submitted today. To view it, please go to: \n",
"http://bigschoolbus.com/asdata2/routes_view.php?electedID=$recID Changes done by {$memberInfo['username']}: \n\n".
$messageData,
// sender address
"From: [email protected]"
);
return TRUE;
}
Re: Email after inser does not work
Posted: 2014-03-05 10:51
by a.gneady
Hmm ... the mail command looks fine ... Is mail working in other scripts? Try making a test script to check if your server is able to send mails correctly:
Save and upload the above script to your server and open it in your browser ... If you see any error messages, please post them here.
Re: Email after inser does not work
Posted: 2014-03-26 17:34
by toconnell
no errors.. I do have email authentication on but this ip is included so it is sending fine. I have other programs that send from this server no issues.
I have bout 20 apps on it.
thanks, Tina
Re: Email after inser does not work
Posted: 2014-04-14 18:43
by toconnell
I got it to work..
for emailing changes to record it does not go into after insert.. it goes after_update function instead.. that fixed it.
here is the code.. for anyone else who needs it.
Code: Select all
function YourTableName_after_update($data, $memberInfo, &$args){
foreach($data as $field => $value){
$messageData .= "$field: $value \n";
}
$recID=mysql_insert_id();
sql("insert into membership_userrecords set tableName='YourTableName' , pkValue='#recID',
memberID=' ".getLoggedMemberID()."', dateAdded=' ".time()."', dateUpdated='".time()."',
groupID= ".getLoggedGroupID().".", $eo);
@mail(
// mail recipient
"[email protected], [email protected]",
// subject
"A Record in the Driver Compliance table of the database was changed - notification - Driver RECORD NUMBER-{$data['Record_Id']}",
// message
"The above record {$data['Record_Id']} was just modified by:{$memberInfo['username']} The record was updated on and by:{$data['LastUpdatedby']} \n To view the record please go to \n http://YourDomainName.com/YourAppGiniFileFolder/YourTableName_view.php?SelectedID=".$data['selectedID']." Newly entered data shows as actual table values below:,
{$messageData} \n. The user that changed this record did so from IP Address: {$memberInfo['IP']} \n\n",
// sender address
"[email protected]"
);
return TRUE;
}
Re: Email after inser does not work
Posted: 2014-04-17 00:41
by KSan
Yayy!!! You are now the resident expert on this topic! I know who I'm asking when I try this in my project. Thanks for sharing your findings.
Re: Email after inser does not work
Posted: 2014-04-17 20:05
by toconnell
LOL OK KSAN.. OK.. now help me with my audit trail : ) LOL So glad I can help
Your a good coder ...maybe we can trade off ...
I found this..
https://www.simple-talk.com/sql/databas ... dit-trail/
and I want to do the audit in the same database with a new table called audit or historical log.. using a trigger I can do this.. my problem for not being able to copy and paste this code right into a trigger and do this is that I have shared hosting, my sql database is accessed through phpmyadmin and it won't take sql server commands in the sql tab, just basic sql.. or I can create a trigger but never done it before.
The tables I want to track are bus_status, compliance and routes
and I want to track only the data that is changed. Right now I have it tracking everything which is making the audit table I have temporarily working quite large. Not good.
If it will only capture the changed data we don't do many transactions per day (like 20 total for all users) so it is not a big deal.
Your thoughts on how best to do that?
Re: Email after inser does not work
Posted: 2014-04-18 02:23
by KSan
Good question to branch off into but too offtopic for the original post. Can you kindly start a new thread for this one? Thanks
Re: Email after inser does not work
Posted: 2014-04-18 12:38
by toconnell
Actually you can put that code above in both after_insert hook and the after_update hook (e.g. tablename_after_insert or tablename_after_update) the after insert happens when a new record is added to the table so it will email then if you put the code there, but if you want it ti email just updates to existing records the tablename_after_update hook will be where you want to put that code.. then perfection. Be sure you change the table name to your table name and the emails to your emails.
Thanks,Tina