0
由於評論中的以下建議,我更新了我的代碼。現在的問題是我得到一個錯誤。下面是新的代碼:發送電子郵件給每個符合條件的用戶
<?php
require_once "config.php";
$idspam = "1";
$sql = "SELECT * FROM company WHERE ID = '$idspam'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$companyname = $row['CompanyName'];
}
$sql = "SELECT * FROM users";
$result = mysql_query($sql);
$rows = mysql_fetch_array($result);
foreach($rows as $row)
{
$Agent = $row['username'];
$fullname = $row['fullname'];
$phone = $row['phone'];
$Agentmail = $row['mail'];
$checkstat = "New customer";
$result = mysql_query("SELECT * FROM data WHERE Status = '$checkstat' AND Agent = '$Agent'");
$rows = mysql_fetch_array($result);
foreach($rows as $row)
{
$LastName = $row['LastName'];
if (empty($row['ProductPriceUSD'])) {
$ProductPriceEUR = $row['ProductPriceEUR'];
$symbol = "€";
$Productprice = ($ProductPriceEUR . $symbol);
}
if (empty($row['ProductPriceEUR'])) {
$ProductPriceUSD = $row['ProductPriceUSD'];
$symbol = "$";
$Productprice = ($symbol . $ProductPriceUSD);
}
$CustomerPriceRAW = $row['CustomerPrice'];
$eur = "€";
$email = $row['Email'];
$a = mt_rand(100000,999999);
$MD5Pass = md5($LastName . $a);
$type = "Initial";
$sql = "SELECT * FROM emails WHERE AddedBy = '$Agent' ORDER BY RAND() LIMIT 1";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$content = $row['Content'];
$subject = $row['Subject'];
}
$Newstatus = "Contacted";
$Newline = "<br>";
$replaceWord = array(
"[name]" => $row['FirstName'],
"[lastname]" => $row['LastName'],
"[product]" => $row['ProductName'],
"[username]" => $row['CustomerUser'],
"[agent]" => $row['Agent'],
"[productssold]" => $row['ProductsSold'],
"[customerprice]" => ($CustomerPriceRAW . $eur),
"[password]" => ($LastName . $a),
"[productprice]" => $Productprice,
"[newline]" => $Newline,
);
ob_start();
include("./email/mailtemplate.php");
$sendmsg = ob_get_clean();
$message = $sendmsg;
$body = strtr($content, $replaceWord);
$headers = "From:".$companyname." ".$Agentmail."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$contactdate = date("Y-m-d");
$sevendays = date('Y-m-d', strtotime("+7 days"));
$todo = "Followup";
mysql_query("UPDATE data SET CustomerPass = '$MD5Pass', Status = '$Newstatus', Contacted = '$contactdate', SevenDays = '$sevendays', ToDo = '$todo'");
mail($email, $subject, $body, $headers);
}
}
?>
,這裏是錯誤,我得到
Warning: Invalid argument supplied for foreach() in /home/user/public_html/cronmailinitial.php on line 22
爲什麼?我想挑選我的所有員工(第一次),並聯系他們的每個客戶。因此,一個例子是: 對於代理「約翰」 截齒,「約翰」 增加對他們每個人的所有客戶選擇不同的電子郵件模板 發送
這就是它的假設也是閒着。在此先感謝
賀雅,我知道這是現在改變它已經太晚了,它會在更新中被修改。 '$ result = mysql_query(「SELECT * FROM data WHERE Status ='$ checkstat'」); while($ row = mysql_fetch_array($ result))' 是我在哪裏將'while'更改爲'foreach'就像您所說的,並且將電子郵件模板選擇代碼從開頭遷移到那個? –
將mysql_fetch_array放在它自己的行上。不要循環它。使用此調用的結果來循環值。它返回一個數組。 – ethrbunny
我已更新我的代碼,但這次我收到新錯誤 –