PHP - 将表行数据发送到电子邮件地址为行数据的电子邮件

时间:2017-08-08 09:59:59

标签: php mysql sql email pdo

我目前正在开发票务系统。我的按钮功能有问题。该按钮有两个功能,一个是将表行数据发送到另一个表,第二个是向用户发送一封电子邮件,通知该票证已经完成。电子邮件的地址或接收者也从表格行中获取。将表行发送到另一个表的代码正在运行,但是将表行数据发送到电子邮件的代码根本不起作用。有人可以帮我解决这个问题吗?

<?php
require_once 'database.php';

$id = null;

if ( !empty($_GET['id'])) {
    $id = $_REQUEST['id'];
}
if ( null==$id ) {
    header("Location: closed.php");
}else{

    $pdo = Database::connect();
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sqlii = "UPDATE tickets SET ticketStatus='DONE'  WHERE ticketId = ?";
    $qii = $pdo->prepare($sqlii);
    $qii->execute(array($id));
    Database::disconnect();

    $pdo = Database::connect();
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "INSERT INTO closedtickets SELECT * FROM tickets where ticketId = ?";
    $q = $pdo->prepare($sql);
    $q->execute(array($id));
    Database::disconnect();

    $pdo = Database::connect();
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sqliii = "DELETE FROM tickets  WHERE ticketId = ?";
    $qi = $pdo->prepare($sqliii);
    $qi->execute(array($id));
    Database::disconnect(); 

    $pdo = Database::connect();
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sqliii = "SELECT * FROM closedtickets  WHERE ticketId = ?";
    $qi = $pdo->prepare($sqliii);
    $qi->execute(array($id));
    Database::disconnect(); 
} 

/* The php script below is not working
// include phpmailer class */

require_once 'phpmailer.php';
/* creates object */
$mail = new PHPMailer(true);  

if(isset($_POST['id']))
{
    $pdo = Database::connect();
    $sql = 'SELECT * FROM closedtickets WHERE ticketId = ?'; 
    foreach ($pdo->query($sql) as $row) {

        $full_name  = ($_SESSION['adminName']);
        $email      = "email@email.com.ph";
        $admin = "admin@admin.com.ph";
        $ticketRefNum = $row['ticketRefNum'];
        $ticketDate = $row['ticketDate'];
        $ticketSubject = $row['ticketSubject'];
        $ticketReceiver = $row['ticketReceiver'];
        $ticketEmail = $row['ticketEmail'];
        $ticketStatus = $row['ticketStatus'];
        $text_message    = "From: IT Service Desk <br /> Ticket Date: $ticketDate 
        <br /> To: $ticketReceiver <br /> Subject: [Reference Number: 
        $ticketRefNum] $ticketSubject <br /> Ticket Status: $ticketStatus <br /> 
        <br /> <br /> Hi $ticketReceiver, your ticket about $subject has already 
        been done by the IT.";         

        /* email content */
        $message  = "$text_message";
    }
    Database::disconnect(); 

    /* SMTP Set up */
    try {
        $mail->IsSMTP(); 
        $mail->isHTML(true);
        $mail->SMTPDebug  = 0;                     
        $mail->SMTPAuth   = true;                  
        $mail->SMTPSecure = "ssl";                 
        $mail->Host       = "smtp.smtp.com";      
        $mail->Port       = 465;             
        $mail->AddAddress($ticketEmail);
        $mail->Username   ="email@email.com";  
        $mail->Password   ="password";            
        $mail->SetFrom($email,"Ticket");
        $mail->AddReplyTo($admin,"Ticket");
        $mail->Subject    = $ticketSubject;
        $mail->Body     = $message;
        $mail->AltBody    = $message;

        if($mail->Send()) {

          $msg = "<div class='alert alert-success'>
              Hi,<br /> ".$full_name." mail was successfully sent to ".$email." 
      go and check, cheers :)
              </div>";
        }
    }
    catch(phpmailerException $ex) {
        $msg = "<div class='alert alert-warning'>".$ex->errorMessage()."</div>";
    }
}
?>

0 个答案:

没有答案