Send email on insert?

QuestionsSend email on insert?
Gary Brett asked 5 years ago

Hello Abu, I wonder if it's possible to view the insert code for the add new record form? When I add a new record I think it would be great to be able to autosend an html email to the user with forms details in body? I've done this before but not use g phpgrid?

Kind regards


6 Answers
Abu Ghufran answered 5 years ago


You can do it using on_insert event handler.
It basically inject your custom code before the insert operation of grid.

You can also use on_after_insert.

Complete options and sample code can be checked in demos/editing/custom-events.php

Gary Brett answered 5 years ago

Hi Abu, again thank you. Do you have any demos or code to achieve this at all? I have the below code which sends an email from my hosting but no idea how to pull the grid form data through and add to insert code of gridfrom?

ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "[email protected]";
$to = "[col: email]";
$subject = "PHP Mail Test script";
$message = "All phpgrid fields here";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
echo "Test email sent";

Thank you very much sure it would be useful demo for us staters 🙂

Abu Ghufran answered 5 years ago

Here is sample code:

This is not tested. It is just to give an idea how to use on_insert event and it's data.

Abu Ghufran answered 5 years ago


Please email me your code. i'll integrate it to help your understand. You can email me at [email protected]

Btw, the comments in the hastebin link were not be uncommented. It was written:
"These comments are just to show the input param format"

Gary Brett answered 5 years ago

Hi Abu, much appreciated & I know it was untested so no problems. As a test I have added the code to a working grid, once I remove the comments it starts to throw errors on line $data => Array as below.

If I change to == it then passes that line but errors on all lines below, looking at the custom vents demo that code seems fine so I must be looking in the wrong place, is $data => Array the correct code?

function add_client($data)

$data => Array
[params] => Array
[client_id] =>
[name] => Test
[gender] => male
[company] => Comp


$msg = "";

If any of the users who have purchased read this and indeed have a working example I would very much appreciate the assistance, this is a key function in my project to have clients emailed on insert?

Thank you so much

Gary Brett answered 5 years ago

Hi Abu, I don't have the knowledge to implement this so am tackling it another way. Wondered if you could tell me where the View Record form is stored, I want to add some code and a button to it that will email the forms data, seems easier than emailing on insert.

Your Answer

15 + 0 =

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?