After_Insert Hook

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
gatenet
Veteran Member
Posts: 45
Joined: 2016-07-26 09:34
Location: Greece
Contact:

After_Insert Hook

Post by gatenet » 2018-01-12 09:40

I am trying to send an email to admin when a user insert a new record and my code is this

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

/* send an email notification when a new order is placed */
ob_start(); ?>
<h3>You have a new record:</h3>
<hr>
<table>
<tr><td><b>id</b></td><td><?php echo $data['id']; ?></td></tr>
<tr><td><b>Date</b></td><td><?php echo date('d/m/y', strtotime($data['Hmerominia'])); ?></td></tr>
<tr><td><b>Partner</b></td><td><?php echo sqlValue("select Name from Sinergates where id='" . makeSafe($data['id']) . "'"); ?></td></tr>
<tr><td><b>Customer</b></td><td><?php echo sqlValue("select Name from Pelates where id='" . makeSafe($data['id']) . "'"); ?></td></tr>
<tr><td><b>Company</b></td><td><?php echo sqlValue("select Etaireia from Etaireies where id='" . makeSafe($data['id']) . "'"); ?></td></tr>

</table>
<?php
$mail_body = ob_get_contents();
ob_end_clean();

//$customer_email = sqlValue("select email from customers where CustomerID='" . makeSafe($data['CustomerID']) . "'");

mail(
'[email protected]',
'New order placed ' . $data['id'],
$mail_body,
"From: [email protected]\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-type: text/html; charset=Unicode UTF-8\r\n"
);
return TRUE;
}

Nothing is happening what am i doing wrong?
Thank you

R Tammam
Veteran Member
Posts: 113
Joined: 2017-08-26 15:35

Re: After_Insert Hook

Post by R Tammam » 2018-01-15 10:03

try to use send mail function and here's it's parameters
sendmail(array(
'to' => $email,
'name' => $memberID,
'subject' => $adminConfig['approvalSubject'],
'message' => nl2br($adminConfig['approvalMessage'])
));

User avatar
fbrano
Veteran Member
Posts: 70
Joined: 2018-03-19 10:39
Location: Slovakia
Contact:

Re: After_Insert Hook

Post by fbrano » 2018-05-29 15:38

//My great thanks to a.gneady

function Pristupy_after_insert($data, $memberInfo, &$args){
$groupID = 2; // change this to the actual group ID you wish to email
$emails_arr = array();
$res = sql("select email from membership_users where groupID='{$groupID}' ", $eo);
while($row = db_fetch_assoc($res)) $emails_arr[] = $row['email'];
$emails = implode(',', $emails_arr);
// 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";
}
// now send your email
//@mail($emails, $subject, $messageData, "From: [email protected]");
@mail(
// mail recipient
$emails,
// subject
"New record added to table Pristupy",
// message
"Record was created by user {$memberInfo['username']}: \n\n".
$messageData,
// sender address
"From: [email protected]"
);
return TRUE;
}
ver 23.15 1484

Post Reply