Trying to send an email upon insert

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
utony
Veteran Member
Posts: 93
Joined: 2020-04-03 18:37

Trying to send an email upon insert

Post by utony » 2023-08-23 23:12

I have looked at all the old documentation on this, but I am not able to get it to work.

anyone? Code examples, location, etc. please and thank you!

utony
Veteran Member
Posts: 93
Joined: 2020-04-03 18:37

Re: Trying to send an email upon insert

Post by utony » 2023-08-24 20:06

tablename_after_insert()
Called after executing the insert query (but before executing the ownership insert query). If you open the generated hooks/tablename.php file in a text editor (where tablename is the name of the concerned table), you can see this function defined as follows:
1
2
3
4
function tablename_after_insert($data, $memberInfo, &$args){

return true;
}

Parameters:
$data is an associative array where the keys are field names and the values are the field data values that were inserted into the new record. It also includes the item $data['selectedID'] which stores the value of the primary key for the new record.
$memberInfo is an array containing details of the member who signed in. Please refer to memberInfo for more details.
$args is currently not used but is reserved for future uses.

Return value:
A boolean true to perform the ownership insert operation or false to cancel it. Warning: if a false is returned, the new record will have no ownership info.


Example:
The following example sends a notification email to an employee when a user submits a new record. The email contains the record data.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function tablename_after_insert($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";
}

sendmail(array(
'to' => 'employee@company.com',
'name' => 'Recipient Name',

'subject' => 'A new record needs your attention',

'message' => "The following new record was submitted by {$memberInfo['username']}: \n\n" . $messageData
));

return true;
}

pasbonte
Veteran Member
Posts: 158
Joined: 2013-02-06 09:49

Re: Trying to send an email upon insert

Post by pasbonte » 2023-12-02 21:43

bonjour

Essaye :

Code: Select all

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

// DEBUT send an email notification when a new order is placed  CREATION */
 //
ob_start(); ?>
<h3>Important : Nouvelle fiche de demande HSE</h3>
<hr>
<table>
<tr><td><b>NUMERO DE LA FICHE </td><td><?php echo sqlValue("select id from GES_DEMANDE_HSE_2324 where id='" . makeSafe($data['id']) . "'"); ?></td></tr>
<tr><td><b>PORTEUR</td><td><?php echo sqlValue("select NOM from GES_DEMANDE_HSE_2324 where id='" . makeSafe($data['id']) . "'"); ?></td></tr>
<tr><td><b>EMAIL PORTEUR</td><td><?php echo sqlValue("select HSE_EMAIL from GES_DEMANDE_HSE_2324 where id='" . makeSafe($data['id']) . "'"); ?></td></tr>
<tr><td><b>MONTANT DEMANDE</td><td><?php echo sqlValue("select MONTANT_HSE from GES_DEMANDE_HSE_2324 where id='" . makeSafe($data['id']) . "'"); ?></td></tr>
<tr><td><b>MOIS_HSE</td><td><?php echo sqlValue("select MOIS_HSE from GES_DEMANDE_HSE_2324 where id='" . makeSafe($data['id']) . "'"); ?></td></tr>
<tr><td><b>OBJET :</td><td><?php echo sqlValue("select PROJET_HSE from GES_DEMANDE_HSE_2324 where id='" . makeSafe($data['id']) . "'"); ?></td></tr>
<tr><td><b>AVIS notifié ultérieurement</td><td></td></tr>


<?php
$pk = $data['id'] ?? $data['selectedID'];
$href = "http://www.xxxxxxxxxxxx/GES_DEMANDE_HSE_2324_view.php?SelectedID={$pk}";
$link = "<a href=\"{$href}\">Pour VOIR cette demande Veuillez cliquer ICI</a>";
ECHO $link;
?>
</table>
<?php

$mail_body = ob_get_contents();
ob_end_clean();


@mail(
'xxxxxxxx@xxxxxxxxx.org',
'NOUVELLE FICHE DEMANDE HSE: ' . $data['NOM'],
$mail_body,
"From: xxxxxxxx@xxxxxxx.org\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-type: text/html; charset=iso-8859-1\r\n"
);

@mail(
'xxxxxxxxx@xxxxxxxxx.org',
'NOUVELLE FICHE DEMANDE HSE: ' . $data['NOM'],
$mail_body,
"From: xxxxxxx@xxxxxxxx.org\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-type: text/html; charset=iso-8859-1\r\n"
);

$user_email = sqlValue("select HSE_EMAIL from GES_DEMANDE_HSE_2324 where id='" . makeSafe($data['id']) . "'");
//$user_nom = sqlValue("select NOM from GES_DEMANDE_HSE_2324 where id='" . makeSafe($data['id']) . "'");
//$user_projet = sqlValue("select PROJET from GES_DEMANDE_HSE_2324 where id='" . makeSafe($data['id']) . "'");
//$user_montant = sqlValue("select MONTANT_HSE from GES_DEMANDE_HSE_2324 where id='" . makeSafe($data['id']) . "'");
@mail(
			"$user_email",
			'COLLEGE F PONSARD -----> NOTIFICATION FICHE DEMANDE  HSE : ' . $user_nom ." " . $user_projet,
			$mail_body,
			"From: xxxxxxxxl@xxxxxxx.org\r\n" .
			"MIME-Version: 1.0\r\n" .
			"Content-type: text/html; charset=iso-8859-1\r\n"
	);		
	
$mail_body = ob_get_contents();
ob_end_clean();

 // FIN envoi MEL
in HOOKS et ton fichier

Post Reply