簡體   English   中英

如何在mysql數據庫中更新值時自動發送電子郵件

[英]how to send email automatically when a value is updated in mysql database

我設計了一個應用程序,並使用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);

    }
?>

告訴我是否有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM