Editor - PHP On Postcreate - Mail error

Editor - PHP On Postcreate - Mail error

somehumansomehuman Posts: 7Questions: 2Answers: 0

In server-side PHP, I'm trying to send an email when the postCreate event is fired. I'd then like to trap the editor postCreate event on the client side to present a messagebox that the email was sent.

Similar to this: https://datatables.net/blog/2015-10-02#E-mail-notification

I have the server side and client side working without actually sending the email (via the PHP mail command). The events fire correctly.

When I add the mail command in the server code, the event does not fire on the client side. I assume that the JSON response is not being sent back correctly - I let the editor code send the response back, I don't do it explicitly.

Below is my server side PHP code:
You can see the mail command (with dummy email addresses). The email will send OK, but the client side postCreate event does not fire. If I remove the mail line of code, the client side event fires just fine. What is the PHP mail command doing that causes this?

All help is appreciated!

Thanks
Tim

<?php
// DataTables PHP library
include( "../vendor/datatables-editor/lib/DataTables.php" );

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db_abb, 'nomination' )
    ->fields(
        Field::inst( 'nomination.id' ),
        Field::inst( 'nomination.owner' ),
        Field::inst( 'nomination.ownername' ),
        Field::inst( 'nomination.nominees' ),
        Field::inst( 'nomination.s_nominees' ),
        Field::inst( 'nomination.others' ),
        Field::inst( 'nomination.categories' ),
        Field::inst( 'nomination.s_categories' ),
        Field::inst( 'nomination.reason' ),
        Field::inst( 'nomination.createddt' )
            ->getFormatter( Format::dateSqlToFormat( 'm/d/Y H:i' ) )
    )
    ->on( 'postCreate', function ( $e, $id, $values, $row ) {
        mail('myemail@somewhere.org','My Subject','My Email Body','From: someone@somewhere.org');
    })  
    ->process( $_POST )
    ->json();
?>

Replies

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    I assume that the JSON response is not being sent back correctly

    If that is the case, what is it sending back? You'll be able to see in the browser's Network Inspector view. It could be that PHP is throwing a warning, or something else.

    Thanks,
    Allan

  • somehumansomehuman Posts: 7Questions: 2Answers: 0

    I found my issue:

    In my Javascript button click event handler, where I call the editor.create function, I had to insert a "return false;" at the end of the function (the button click event handler function). Without it the function wasn't ending correctly.

    Thanks for your help.
    Tim

This discussion has been closed.