Hia Abu,
I need to send an email after updating a record to the email associated with the record. The following is my code for the on_update envent. I don’t understand how to get at the email data in the $data array. Can you assist?
//Send notification email $e["on_update"] = array("send_notification", null, true); $g->set_events($e); function send_notification($data) { require"../functions/dbconn.php"; $sql = 'select appvar_value from appvars where appvar_name ="registration_sender"'; $result = $con->query($sql); while($row = $result->fetch_assoc()) { $from = $row["appvar_value"]; } $e="{$data['params']['employee_sak']}"; $sql = "select email from employee where employee_sak =".$e; $result = $con->query($sql); while($row = $result->fetch_assoc()) { $to = $row["email"]; } //$to=$data["email"]; // To send HTML mail, the Content-type header must be set $to=$to; $subject = 'the subject'; $message = 'hello'; $headers = 'MIME-Version: 1.0'."\r\n"; $headers.='Content-type: text/html; charset=iso-8859-1'."\r\n"; $headers.='From: '.$from."\r\n". $from."\r\n". 'X-Mailer: PHP/'.phpversion(); mail($to, $subject, $message, $headers); }
<script src=”https://gist.github.com/moda253/a790d01a2db995b17cf4f48b0a97e355.js”></script>
whoa not sure why that formatted like that
here is the code I need help with. Trying to get the email data from $data on_update
//Send notification email
$e[“on_update”] = array(“send_notification”, null, true);
$g->set_events($e);
function send_notification($data)
{
require”../functions/dbconn.php”;
$sql = ‘select appvar_value from appvars where appvar_name =”registration_sender”‘;
$result = $con->query($sql);
while($row = $result->fetch_assoc()) {
$from = $row[“appvar_value”];
}
$e=”{$data[‘params’][’employee_sak’]}”;
$sql = “select email from employee where employee_sak =”.$e;
$result = $con->query($sql);
while($row = $result->fetch_assoc()) {
$to = $row[“email”];
}
//$to=$data[“email”];
// To send HTML mail, the Content-type header must be set
$to=$to;
$subject = ‘the subject’;
$message = ‘hello’;
$headers = ‘MIME-Version: 1.0′.”\r\n”;
$headers.=’Content-type: text/html; charset=iso-8859-1’.”\r\n”;
$headers.=’From: ‘.$from.”\r\n”.
$from.”\r\n”.
‘X-Mailer: PHP/’.phpversion();
mail($to, $subject, $message, $headers);
}
Your code looks fine.
The $data in “function send_notification($data)” should contain all the editable fields of the grid while doing edit operation.
To debug what you are getting in $data, You can put:
function send_notification($data)
{
phprgid_error($data);
//…
}
This will print the contents of $data in an message box and you can see what’s in it.
Does the field have to be editable? The email field is not a field that will be being edited.
Also that bit of code is an error for me