2014-09-24 87 views
0

我设计了一个应用程序并使用phonegap构建所有工作正常,但是当我的mysql数据库中附加应用程序的值更新时,我希望自动发送电子邮件给用户。当计数器完成对runnind中的“状态”值的计数时,广告表中的数据会更新,并且我希望每次更新该值时发送一封电子邮件,以下是我为要发送的电子邮件编写的脚本,但我不知道如何自动的话,请用什么我能帮助应该还是可以如何在MySQL数据库中更新值时自动发送电子邮件

<? 
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 = "[email protected]"; 
     $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: <[email protected]>' . "\r\n"; 

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

    } 
?> 
+0

请解释一下状况view_running_ads.php – 2014-09-24 11:36:34

回答

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 = "[email protected]"; 
     $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: <[email protected]>' . "\r\n"; 

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

    } 
?> 

告诉我,如果它工作或没有。

+0

@Tatic感谢,但它并没有在所有的工作,请有人可以告诉我怎么触发的作品,是什么事情我可以使用 – Efficacy 2014-09-25 05:32:12

+0

请回答我的问题OOOOO – Efficacy 2014-09-26 12:33:09

+0

帮助@ user3345857最近几天我很忙。我没有时间去做。我明天会尽力帮助你。祝你好运! – 2014-09-26 12:43:05

相关问题