duanfei8149 2014-09-24 11:29
浏览 94

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

i design an application and build with phonegap all is working but when a value in my mysql database that is attached the app is updated i want an email to be sent automatically to the user. When the counter completes counting the value of "status" in runnindAds table is updated and i want to an email to be sent each time that value is updated, below is the script i wrote for the email to be sent but i don't know how to automate it, please help with what i can should or i can

<?
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" . "
";
        $headers .= "Content-type:text/html;charset=UTF-8" . "
";
        $headers .= 'From: <admin@addirectng.com>' . "
";

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

    }
?>
  • 写回答

1条回答 默认 最新

  • dtypj3308 2014-09-24 11:37
    关注

    Try this:

    <?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" . "
    ";
            $headers .= "Content-type:text/html;charset=UTF-8" . "
    ";
            $headers .= 'From: <admin@addirectng.com>' . "
    ";
    
            mail($to,$subject,$message,$headers);
    
        }
    ?>
    

    Tell me if it works or not.

    评论

报告相同问题?