Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 数据表在编辑时发送电子邮件_Php_Email_Datatables - Fatal编程技术网

Php 数据表在编辑时发送电子邮件

Php 数据表在编辑时发送电子邮件,php,email,datatables,Php,Email,Datatables,我需要一些关于如何使用datatables发送电子邮件的帮助。 如果“状态”列中的值更改为“已完成”,我希望向“电子邮件”列中的电子邮件地址发送电子邮件 <?php /* * Editor server script for DB table vehicles */ // DataTables PHP library and database connection include( "lib/DataTables.php" ); session_start(); // Alias

我需要一些关于如何使用datatables发送电子邮件的帮助。 如果“状态”列中的值更改为“已完成”,我希望向“电子邮件”列中的电子邮件地址发送电子邮件

<?php

/*
 * Editor server script for DB table vehicles
 */

// DataTables PHP library and database connection
include( "lib/DataTables.php" );
session_start();
// 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;

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'vehicles' )
    ->fields(
    Field::inst( 'vehicles.email' )
          ->options( Options::inst()
          ->table( 'users' )
          ->value( 'userId' )
          ->label( 'email' )
               )
              ->validator( 'Validate::dbValues' ),
    Field::inst( 'users.email' ),
    Field::inst( 'vehicles.name' )
          ->options( Options::inst()
          ->table( 'users' )
          ->value( 'userId' )
          ->label( 'name' )
               )
              ->validator( 'Validate::dbValues' ),
    Field::inst( 'users.name' ),
    Field::inst( 'vehicles.stock' ),
    Field::inst( 'vehicles.make' ),
    Field::inst( 'vehicles.model' ),
    Field::inst( 'vehicles.color' ),
    Field::inst( 'vehicles.year' ),
    Field::inst( 'vehicles.service' )
            ->options( Options::inst()
            ->table( 'services' )
            ->value( 'service_id' )
            ->label( 'service' )
              )
            ->validator( 'Validate::dbValues' ),
    Field::inst( 'services.service' ),    
    Field::inst( 'vehicles.due' )
        ->validator( 'Validate::dateFormat', array(
            'empty' => false,
            'format' => 'm-d-Y g:i A'
            ) )
                ->getFormatter( 'Format::datetime', array(
            'from' => 'Y-m-d H:i:s',
            'to' =>   'm-d-Y g:i A'
            ) )
            ->setFormatter( 'Format::datetime', array(
            'from' => 'm-d-Y g:i A',
            'to' =>   'Y-m-d H:i:s'
            ) ),
    Field::inst( 'vehicles.notes' ),
    Field::inst( 'vehicles.status' )
            ->options( Options::inst()
            ->table( 'status' )
            ->value( 'status_id' )
            ->label( 'status' )
              )
            ->validator( 'Validate::dbValues' ),
    Field::inst( 'status.status' ),    
    Field::inst( 'vehicles.detailer' )
            ->options( Options::inst()
                    ->table( 'detailers' )
                    ->value( 'detailer_id' )
                    ->label( 'detailer_name' )
                      )
            ->validator( 'Validate::dbValues' ),
    Field::inst( 'detailers.detailer_name' ),    
    Field::inst( 'vehicles.comments' )
    )
    ->leftJoin( 'users', 'users.userId', '=', 'vehicles.name' )
    ->leftJoin( 'services', 'services.service_id', '=', 'vehicles.service' )
    ->leftJoin( 'status', 'status.status_id', '=', 'vehicles.status' )  
    ->leftJoin( 'detailers', 'detailers.detailer_id', '=', 'vehicles.detailer' )
    ->where( function ( $q ) {
    $q->where( 'due', 'DATE_ADD( NOW(), INTERVAL -1 DAY )', '>=', false );
    } )
        ->on( 'preEdit', function ( $editor, $values ) {
            $editor
                ->field( 'vehicles.email' )
                ->setValue( $_SESSION['user'] );
        } )  
    ->process( $_POST )
    ->json();
谢谢。

建议您试试

->on( 'postEdit', function ( $editor, $id, $values, $row ) {
    if ( $values['status'] === "completed" ) {
        my_mail_function();
   }
} )
其中my\u mail\u function()是您定义用于发送电子邮件的php函数。例如,如果要使用库,则可以将mail_函数()设置为:

<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load composer's autoloader
require 'vendor/autoload.php';

function my_mail_function(){

$mail = new PHPMailer(true);                              // Passing `true` 

    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'user@example.com';                 // SMTP username
    $mail->Password = 'secret';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('from@example.com', 'Mailer');
    $mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
    $mail->addAddress('ellen@example.com');               // Name is optional
    $mail->addReplyTo('info@example.com', 'Information');
    $mail->addCC('cc@example.com');
    $mail->addBCC('bcc@example.com');

    //Attachments
    $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
}

虽然我反对查询构建类,但这是一个超越顶部的类。自己编写sql不是更容易吗?
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load composer's autoloader
require 'vendor/autoload.php';

function my_mail_function(){

$mail = new PHPMailer(true);                              // Passing `true` 

    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'user@example.com';                 // SMTP username
    $mail->Password = 'secret';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('from@example.com', 'Mailer');
    $mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
    $mail->addAddress('ellen@example.com');               // Name is optional
    $mail->addReplyTo('info@example.com', 'Information');
    $mail->addCC('cc@example.com');
    $mail->addBCC('bcc@example.com');

    //Attachments
    $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
}