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 = "&#8364;";
            $Productprice = ($ProductPriceEUR . $symbol);
        }
        if (empty($row['ProductPriceEUR'])) {
            $ProductPriceUSD = $row['ProductPriceUSD'];
            $symbol = "$";
            $Productprice = ($symbol . $ProductPriceUSD);
        }
        $CustomerPriceRAW = $row['CustomerPrice'];
        $eur = "&#8364;";
        $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

为什么?我想挑选我所有的员工(第一个 foreach)并联系他们的每个客户。例如: 对于代理“John” 选择由“John”添加的所有客户 为每个客户选择不同的电子邮件模板 发送

无论如何,这就是它应该做的事情。提前致谢

4

1 回答 1

1

两件事情:

  1. 此 API 已弃用
  2. 改变所有

    而($row = mysql_fetch_array($result))

更像是

$rows = mysql_fetch_array( $result );
foreach( $rows as $row )
{
  .. do something with $row....
}
于 2013-08-30T19:10:05.963 回答