gpt4 book ai didi

php - 如何在更新 MYSQL 数据库时向列表发送电子邮件

转载 作者:行者123 更新时间:2023-11-29 21:03:46 25 4
gpt4 key购买 nike

我编写了一个 php 脚本来发送电子邮件。在此脚本中,它检查当前日期是否与 emailfly_date 相等并且电子邮件 = o。如果满足,则电子邮件将发送给用户。此脚本适用于一个用户一次。如果数据库有 5 条记录符合当前条件,它只会将电子邮件发送到最后一个 id。这是什么原因?

ID

250第251章第252章253

它只会将电子邮件发送给 ID 253,但不会发送给其他人。

这是我的代码

<?php

include_once 'dbconnect.php';



$query = "SELECT ID,email, emailfly_date, CURRENT_DATE AS nowtime FROM xxx WHERE reqnum = '' AND email_sent = '0'";

$result = mysql_query($query) or die(mysql_error());

while ($row = mysql_fetch_array($result)) {

$regid = $row['ID'];
$activemail= $row['nowtime'];
/*echo $regid . '<br />';
echo $activemail. '<br />';*/
}


$query = mysql_query("SELECT ID, email, reqnum, emailfly_date, email_sent FROM xxx WHERE ID = '$regid' AND emailfly_date = '$activemail'");

$rowdata = mysql_fetch_array($query);

$ID = $rowdata['ID'];
$email = $rowdata['email'];
$reqnum = $rowdata['reqnum'];
$emailfly_date = $rowdata['emailfly_date'];
$email_sent = $rowdata['email_sent'];


if ($reqnum != '') {
/* echo "not sucess";*/

} elseif ($email_sent == '1') {
/* echo "email already sent";*/

} elseif ($email_sent == '1' && $reqnum != '') {
/* echo "no way to send";*/
}
elseif($email_sent == '0' && $reqnum == '' ){


$ulink = "http://xxx.eewfewt.net/tttt/yyyy.php?ID=$regid";

$to = $email;

$subject = 'hoo'; // Give the email a subject
$message = '

Thanks for Using Trial Version!
If You Wish to Continue with the Monthly Paid Package.

------------------------
Click Below

Site Renewal link: ' . $ulink . '
'.$emailfly_date.'
------------------------ ';


$headers .= 'From:werwerwer.aaa.net' . "\r\n";
$headers .= 'Bcc:ewrwerer.aaa.net' . "\r\n";
mail($to, $subject, $message, $headers);

$upadtequery = mysql_query("UPDATE xxx SET email_sent ='1' WHERE ID = '$regid'");


echo "sucess";

}
else{
echo "bye";

}




?>

最佳答案

$query = mysql_query(.....bla...bla... 到最后 else{
echo “再见”;
}
将所有这些放入您的 while 循环中。另外,如果您从同一个表中获取数据,请尝试使用单个查询。mysql_() 现已弃用。所以尝试使用mysqli_()

关于php - 如何在更新 MYSQL 数据库时向列表发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36996232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com