Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.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 如何在mysql数据库中更新值时自动发送电子邮件_Php_Mysql_Email_Cordova - Fatal编程技术网

Php 如何在mysql数据库中更新值时自动发送电子邮件

Php 如何在mysql数据库中更新值时自动发送电子邮件,php,mysql,email,cordova,Php,Mysql,Email,Cordova,我设计了一个应用程序并使用phonegap进行了构建,但当我的mysql数据库中附加的应用程序的值更新时,我希望自动向用户发送一封电子邮件。计数器完成计数后,runnindAds表中的状态值将更新,并且我希望在每次更新该值时发送一封电子邮件,下面是我为发送电子邮件编写的脚本,但我不知道如何实现自动化,请帮助我做些什么 <? include('../db_connect.php'); require_once "PHPMailer-master/class.phpmailer.php";

我设计了一个应用程序并使用phonegap进行了构建,但当我的mysql数据库中附加的应用程序的值更新时,我希望自动向用户发送一封电子邮件。计数器完成计数后,runnindAds表中的状态值将更新,并且我希望在每次更新该值时发送一封电子邮件,下面是我为发送电子邮件编写的脚本,但我不知道如何实现自动化,请帮助我做些什么

<?
include('../db_connect.php');
require_once "PHPMailer-master/class.phpmailer.php";

$id=$_GET["rid"];
$status = 3;
mysql_query("update runningAds set status = 3 where id = '$id'");

// get username
$qaz = mysql_query("select * from runningAds where id = $id") or die (mysql_error());
$wsx = mysql_fetch_array($qaz);
$username = $wsx["users"];
$stopTime = $wsx['stopTime'];

sendConfirmationEmail($username, $stopTime);

header("location: ../view_running_ads.php");

function sendConfirmationEmail($username, $stopTime)
    {
        $result2 = mysql_query("select * from dapUsers where userName='$username'");
        $row = mysql_fetch_array($result2);


        $to = $row['email'];
        //$from = "admin@addirectng.com";
        $subject = 'Advert Runtime Alert';
        $message = "Dear $username,<br \>
        Your display picture advert runtime has ended at $stopTime. <br \>
        Advert Direct Team";

        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
        $headers .= 'From: <admin@addirectng.com>' . "\r\n";

        mail($to,$subject,$message,$headers);

    }
?>
试试这个:

<?php
include('../db_connect.php');
require_once "PHPMailer-master/class.phpmailer.php";

$id=$_GET["rid"];
$status = 3;

 // get username
$qaz = mysql_query("select * from runningAds where id = $id") or die (mysql_error());
$wsx = mysql_fetch_array($qaz);
$username = $wsx["users"];
$stopTime = $wsx['stopTime'];

if (mysql_query("update runningAds set status = 3 where id = '$id'"))
{
     sendConfirmationEmail($username, $stopTime);
}





header("location: ../view_running_ads.php");

function sendConfirmationEmail($username, $stopTime)
    {
        $result2 = mysql_query("select * from dapUsers where userName='$username'");
        $row = mysql_fetch_array($result2);


        $to = $row['email'];
        //$from = "admin@addirectng.com";
        $subject = 'Advert Runtime Alert';
        $message = "Dear $username,<br \>
        Your display picture advert runtime has ended at $stopTime. <br \>
        Advert Direct Team";

        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
        $headers .= 'From: <admin@addirectng.com>' . "\r\n";

        mail($to,$subject,$message,$headers);

    }
?>

告诉我它是否有效。

请解释更多有关view\u running\u广告状态的信息。php@Tatic谢谢,但它根本不起作用,请有人告诉我触发器是如何工作的,它是我可以使用的吗请帮助回答我的问题ooooo@user3345857前几天我很忙。我没有时间这么做。明天我会尽力帮助你。祝你好运