Need Help With Email Notification

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
mgain2013
Posts: 29
Joined: 2013-02-16 16:12

Need Help With Email Notification

Post by mgain2013 » 2013-05-12 03:49

I could use some help modifying an after_insert and after_update hook. I need to send out an email notification after a record has been inserted or updated. The email address needs to come from a field from another table called arcrequest, and it will be sent from a table called arcapproval. The email field will be called email. I also need to attached the path to the record that has been inserted or updated. The path is http://whatever.com/arcapproval_view.php?SelectID=2 (or whatever the actual record is)

I have not been able to figure out how to insert the email address automatically based on the current record being viewed. I can't use the $memberInfo['email']: as they are not currently logged in.

I hope you can understand what I am looking for. If you need more information, please let me know. I would appreciate any help that anyone in the community can provide.

Many Thanks,
Michael

User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

Re: Need Help With Email Notification

Post by shasta59 » 2013-05-17 14:59

Here is what I do in the hook file for that table:

(I need to, in this example, send out emails notifying a bunch of people based upon a criteria when a new report is entered. The people who are send the email are in another table which lists under which circumstances they should be sent an email.)


function yourtablename_after_insert($data, $memberInfo, &$args){

$result = mysql_query("SELECT * FROM yourtablename WHERE your_field_name LIKE '%your_criteria%'") or die(mysql_error());
while ($row = mysql_fetch_array($result))
mail($row['field_containing_email_address'] , 'subject' , 'your body copy in email', 'From: [email protected]');
return TRUE;
}

Read this to see how to include the record id

http://www.bigprof.com/appgini/tips-and ... al-records

The % signs on either side of your_criteria are wild cards to allow greater flexibility in the lookup. You may or may not need them. I use them due to the complex criteria for lookups I do in my application(s).

Hope this is what you are looking for.

Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -

bambinou
Veteran Member
Posts: 163
Joined: 2013-02-01 15:09

Re: Need Help With Email Notification

Post by bambinou » 2013-05-21 15:22

Hi Alan,

Thank you for sharing, I am trying to learn PHP at the moment, would you mind explain where you found this variable?
&$args

I do not understand why you have added "&".

Regarding LIKE '%your_criteria%

Would you mind giving me an example for this please as I do not understand what you mean.

Regards,

Ben

User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

Re: Need Help With Email Notification

Post by shasta59 » 2013-05-21 16:03

Ben

The &$args is in there from AppGini - I did not add it in - it is a future feature which Ahmad will use for something I guess. Here is the info in the file as generated by AppGini

@param $args
* An empty array that is passed by reference. It's currently not used but is reserved for future uses.


Now on to the % signs.

I put these in so, when the field is searched, it will look for anything matching that criteria. I found, if I did not have those in there it would not return a correct response. See this link/reference. I use a couple of fields to hold multiple values and am looking for only one out of all of those. The % sign(s) insure it will find the correct values.

http://dev.mysql.com/doc/refman/5.0/en/ ... tions.html

Here is a bit of the above document.

With LIKE you can use the following two wildcard characters in the pattern.

Character Description
% Matches any number of characters, even zero characters
_ Matches exactly one character
mysql> SELECT 'David!' LIKE 'David_';
-> 1
mysql> SELECT 'David!' LIKE '%D%v%';
-> 1

I am not sure if this clears it up for you but if not let me know.

Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -

mgain2013
Posts: 29
Joined: 2013-02-16 16:12

Re: Need Help With Email Notification

Post by mgain2013 » 2013-05-22 19:28

Alan,

I am still very new at coding with PHP and I am a little confused (ok a lot confused) how to incorporate what I am trying to do with the sample you have provided. I guess one problem is; I actually need to pull information from two different tables in order to provide the correct information for the email. Listed below is what I have so far in the after_update hook. I need to pull fields called 'name' , 'address' and 'email' from a table called arcrequest. All the other information comes from the table called arcapproval. Arcrequest has a primary id called 'id' ,the arcapproval table is linked to the arcrequest table by linking id from the arcrequest to arcrequest field on the arcapproval table. the content from email need to be after the other emailaddress' If I need to scape what I have so far, that is ok, as long as I pull out the required information. I am sure this is a mess, I have tried to figure this out looking at various samples. Any help would be greatly appreciated. I have tried all kinds of things and I can't quite get it.

Thank You,
Michael

function arcapproval_after_update($data, $memberInfo, &$args){

// to compose a message containing the submitted data,

// we need to iterate through the $data array
foreach($data as $field => $value){
$messageData .= "$field: $value \n ";
}
@mail(
// mail recipient
"[email protected], [email protected] , email would go here",
// subject
"An ARC Status has been Updated by an ARC Member",

// message
"To view it please go to:\n".
"http://www.mywebsitename.org/arcV510b/a ... dID={$data['arcrequest']}\n \n".
" The Name field would probably go here"
" The address field would go here"

"Current Status: {$data['status']} \n \n".
"Comments: {$data['statuscomments1']} \n \n".
"Comment Date: {$data['commentdate']} \n \n".




// sender address

"From: [email protected]"

);

return TRUE;
}

bambinou
Veteran Member
Posts: 163
Joined: 2013-02-01 15:09

Re: Need Help With Email Notification

Post by bambinou » 2013-05-23 19:23

Hi Alan,

Thank you for the reply.
I would like to ask you a few more question please as I am trying to understand the logic of App gini.
When we create a basic code a lot of files are being generated. Now if you wish add more features, you have to use the hooks files, but are these files not getting erased by the app gini new files? This is my current problem, I cannot work out which files should not be erased anymore and which files can because the desktop app do not reference the files but only register which are the ones that have been modified on the first upload, I do not this part really tricky.

Now regarding the PHP side of the hooks, are all the variables from each generated pages featured in the relevant hooks files?
Let's say you wish to take one of the variables and add V.A.T to it, did Appgini creates it's own functions? Or can you use normal PHP functions?

When I will understand a bit more about how AppGini behaves, I will then try out your solution.

I am really lost with the above.

Thank you,

Regards,

Ben

mgain2013
Posts: 29
Joined: 2013-02-16 16:12

Re: Need Help With Email Notification

Post by mgain2013 » 2013-05-28 16:30

I am at my wits end. I have finally figured out why no emails were being sent out using Alan's code above. It had to do with the FROM: "[email protected] My mail server was ignoring it because I was using a gmail account. I had to remove the @yourdomain.com to get it to send. My big problem is I can't figure out how to filter the record to only send the email of the current record, it is sending out the message to every email in my table. Here is what I have:

function arcapproval_after_update($data, $memberInfo, &$args){

$result = mysql_query("SELECT arcapproval.arcrequest,arcrequest.id,arcrequest.email FROM arcapproval,arcrequest WHERE arcapproval.arcrequest = arcrequest.id") or die(mysql_error());
while ($row = mysql_fetch_array($result))
mail($row['email'] , 'An ARC REQUEST HAS BEEN UPDATED BY AN ARC COMMITTEE MEMBER' , 'Please Log into http://myxwebsite.org/arcrequestdatabasev2?signin=1', 'From: glengrovearc');

return TRUE;

}

the tables and main fields I am pulling from are as follows:

------> Table----> arcrequest
------> Field-----> id
------>Field------> email

-------> Table----> arcapproval
-------> Field-----> arcrequest (is an ID column)

Any help from anyone would be very mush appreciated, as this has brought my project to a screeching halt. I am sure this seems simple to most of you, but as a novice I am stuck..

Many Thanks,
Michael

mgain2013
Posts: 29
Joined: 2013-02-16 16:12

Re: Need Help With Email Notification

Post by mgain2013 » 2013-05-29 12:03

I finally figured it out....It turned out to be a very simple code..Hope this helps someone else..

$result = mysql_query("SELECT arcrequest.id, arcrequest.email
FROM arcrequest
WHERE arcrequest.id = {$data['arcrequest']}") or die(mysql_error());
while ($row = mysql_fetch_array($result))
mail($row['email'] , 'An ARC REQUEST HAS BEEN UPDATED BY AN ARC COMMITTEE MEMBER' , 'To View Record Please Log into http://yourwebsite.org/arcrequestdatabasev2?signin=1', 'From: arccommittee');

return TRUE;
}



Thanks,
Michael

Post Reply