2014-09-24 124 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

相關問題