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

时间:2014-09-24 11:29:49

标签: php mysql email cordova

我设计一个应用程序并使用phonegap进行构建都工作正常但是当我的mysql数据库中附加了应用程序的值更新时,我希望将电子邮件自动发送给用户。当计数器完成对" status"的值的计数时在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);

    }
?>

1 个答案:

答案 0 :(得分:0)

试试这个:

<?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);

    }
?>

告诉我它是否有效。