Link to record in email after insert

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
benzoD
Veteran Member
Posts: 69
Joined: 2013-01-31 21:16

Link to record in email after insert

Post by benzoD » 2014-02-13 15:33

Hi,

I have emails sent to several people when a record is created or updated. I needed to have a link to the record sent in the email but the tutorial for sending emails with hooks didn't have it included, and the tutorial that did have it was old, using pre-hooks variables and functions.

I thought I'd document it for all. Even though it's drop-dead simple, it took me a while to get it right.

This is the tutorial code:

Code: Select all

// message
"The following new record was submitted by {$memberInfo['username']}: \n\n".
$messageData,
This is what I've changed:

Code: Select all

// message
		"The following new record was submitted by {$memberInfo['username']} at  \n\n http://mydomain.com/app/tablename_view.php?SelectedID=".$data['selectedID']." \n\n".
		$messageData,
Simple.

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

Re: Link to record in email after insert

Post by toconnell » 2014-04-02 17:44

Benzo.. I am sooo stuck on this.. trying for ages.. would you mind emailing your whole working mail script to me? Minus your private info.. of course? My email is tinaATbigschoolbusDOTcom

Thanks so much!
Tina O'Connell
Web Dev & Appgini FAN

benzoD
Veteran Member
Posts: 69
Joined: 2013-01-31 21:16

Re: Link to record in email after insert

Post by benzoD » 2014-04-17 14:09

Sure, Tina. Sorry for the delay but I'll also send this to your email.

The full code, from tip to tail, is here:

Code: Select all

	function tablename_after_insert($data, $memberInfo, &$args){
                        	
	// specify what fields to send through email.  Only need to change 'field1' through 'field6', like 'dateCreated', 'priority', 'status', etc.
	$fields_to_send = array('field1', 'field2', 'field3', 'field4', 'field5', 'field6',);  
            foreach($fields_to_send as $field){
                $messageData .= "$field: {$data[$field]} \n";
	}

	@mail(
		// mail recipients ($memberInfo['email'] is the email of the user that created the record)
		"[email protected], {$memberInfo['email']}", 
		
		// subject
		"{$memberInfo['username']} created a new Record",
		
		// message - $messageData is the fields you selected above, and \n is a line break
		"The following new record was submitted by {$memberInfo['username']} at \n\n http://mycompany.com/tablename_view.php?SelectedID=".$data['selectedID']." \n\n".
		$messageData,
                        
                // sender address - specifiy where the email will be From:
		"From: [email protected]"
	);

		return TRUE;
I hope this helps!

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

Re: Link to record in email after insert

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

Ben,

I got this working.. I sent you the code but it is also here.. just in case anyone else is looking..

http://forums.appgini.com/phpbb/viewtopic.php?f=7&t=898
Tina O'Connell
Web Dev & Appgini FAN

Post Reply