send-an-email-on_update

Questionssend-an-email-on_update
Mike Olson asked 2 years ago

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&gt;

4 Answers
Mike Olson answered 2 years ago

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);
}

Abu Ghufran Staff answered 2 years ago

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.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Mike Olson answered 2 years ago

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

View post on imgur.com

Abu answered 2 years ago

So sorry,. It’s a typo. It should be phpgrid_error($data);

Your Answer

6 + 11 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?