Email after inser does not work

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Email after inser does not work

Post by RonP » 2013-12-15 15:37

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;
	}

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Email after inser does not work

Post by a.gneady » 2014-01-02 19:22

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){
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Email after inser does not work

Post by RonP » 2014-01-04 11:29

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

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: Email after inser does not work

Post by toconnell » 2014-03-04 19:09

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;

	}
Tina O'Connell
Web Dev & Appgini FAN

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Email after inser does not work

Post by a.gneady » 2014-03-05 10:51

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:

Code: Select all

<?php
   mail(
     "[email protected]", /* better set this to an external email outside your server */
     "Test",
     "If you receive this, mail is working",
     "From: [email protected]"
  );
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.
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: Email after inser does not work

Post by toconnell » 2014-03-26 17:34

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
Tina O'Connell
Web Dev & Appgini FAN

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: Email after inser does not work

Post by toconnell » 2014-04-14 18:43

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;

   }
   
Tina O'Connell
Web Dev & Appgini FAN

KSan
AppGini Super Hero
AppGini Super Hero
Posts: 252
Joined: 2013-01-08 20:17

Re: Email after inser does not work

Post by KSan » 2014-04-17 00:41

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.

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: Email after inser does not work

Post by toconnell » 2014-04-17 20:05

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?
Tina O'Connell
Web Dev & Appgini FAN

KSan
AppGini Super Hero
AppGini Super Hero
Posts: 252
Joined: 2013-01-08 20:17

Re: Email after inser does not work

Post by KSan » 2014-04-18 02:23

Good question to branch off into but too offtopic for the original post. Can you kindly start a new thread for this one? Thanks

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: Email after inser does not work

Post by toconnell » 2014-04-18 12:38

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
Tina O'Connell
Web Dev & Appgini FAN

Post Reply