send email on column edit

send email on column edit

hbanaharishbanaharis Posts: 32Questions: 14Answers: 3
edited November 2017 in Editor

I would like to use PHPMailer to send an email on datatable edit event.

When a column value is altered I would like to collect a number of associated row values and pass them via ajax to a php page which will then use PHPMailer to send the email.

What is an example of collecting row data in order to use them in an ajax function?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Are you using Editor here, and you want to send an e-mail when a value changes? If so, the server-side events are how to do this.

    The blog post that introduced server-side events for Editor has an example of how you might send e-mail with the events.

    Allan

  • hbanaharishbanaharis Posts: 32Questions: 14Answers: 3
    edited November 2017

    Im using the editor and noted the example you cited:

    ->on( 'postEdit', function ( $editor, $id, $values, $row ) {
        mail( 'myself@localhost', 'Row edited', 'Row with id '.$id.' edited' );
    } )
    

    Could you please provide an example using PHPMailer instead of the C# mail script

  • hbanaharishbanaharis Posts: 32Questions: 14Answers: 3
    edited November 2017

    adding this

    ->on( 'postEdit', function ( $editor, $id, $values, $row ) {
            echo("<script>console.log('PHP: ');</script>");
        })
    

    creates a system error

  • hbanaharishbanaharis Posts: 32Questions: 14Answers: 3
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Could you please provide an example using PHPMailer instead of the C# mail script

    Sorry, I can't provide support for a third party script such as PHPMailer. The example you show above actually uses PHP's built in mail method, it doesn't use any C# there. The PHPMailer documentation includes an example showing how you can use their software.

    Regarding the error - that's because the server will no longer be returning valid JSON as explained in the tech note. Editor expects valid JSON to be returned, but that echo statement makes it invalid. If you are trying to do some logging, I would suggest using PHP's error_log() function and watching the server's error log.

    Allan

  • hbanaharishbanaharis Posts: 32Questions: 14Answers: 3
    edited December 2017

    Im not suggesting you support PHPmailer, Im requesting that you provide an example of how a script like PHPmailer could be integrated in a postEdit context. The php mail function has a number of constraints that PHPmailer overcomes and having programmatic email control enhances the value of datatables.

    If its simply not possible to use a call to PHPmailer script within ->('postEdit', ... ) please say so and perhaps suggest another way to the PHPmailer script on an edit. Thanks

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓

    I'm afraid I'm not really sure what you are looking for. This is how you could use PHPMailer inside postEdit, just as you would with any other PHP code:

    $editor->on( 'postEdit', function ( $editor, $id, $values, $row ) {
      $mail = new PHPMailer(true);
       ... do something with $mail
    } );
    

    Is that okay to get you started?

    Allan

This discussion has been closed.