Page 1 of 1

Link to record in email after insert

Posted: 2014-02-13 15:33
by benzoD
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.

Re: Link to record in email after insert

Posted: 2014-04-02 17:44
by toconnell
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!

Re: Link to record in email after insert

Posted: 2014-04-17 14:09
by benzoD
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!

Re: Link to record in email after insert

Posted: 2014-04-17 20:06
by toconnell
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