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