Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';不要让这封自动电子邮件在php中工作。你能帮助我吗?_Php_Mysql - Fatal编程技术网

Can';不要让这封自动电子邮件在php中工作。你能帮助我吗?

Can';不要让这封自动电子邮件在php中工作。你能帮助我吗?,php,mysql,Php,Mysql,我正在尝试制作这个秘密的圣诞老人自动电子邮件脚本,它真的让我困惑。。。它不能正确地发送电子邮件(一个人收到大量电子邮件,其他人没有收到任何…) 我试图在for循环中更改数组的长度,我做得对吗 我使用了shuffle函数和email函数,它们似乎工作得很好(除了email函数上的for循环之外——我做得对吗?)。这是我需要帮助的主要功能 代码如下: <?php function twodshuffle($array) { // Get array length $count

我正在尝试制作这个秘密的圣诞老人自动电子邮件脚本,它真的让我困惑。。。它不能正确地发送电子邮件(一个人收到大量电子邮件,其他人没有收到任何…)

我试图在for循环中更改数组的长度,我做得对吗

我使用了shuffle函数和email函数,它们似乎工作得很好(除了email函数上的for循环之外——我做得对吗?)。这是我需要帮助的主要功能

代码如下:

<?php
function twodshuffle($array)
{
    // Get array length
    $count = count($array);
    // Create a range of indicies
    $indi = range(1,$count);
    // Randomize indicies array
    shuffle($indi);
    // Initialize new array
    $newarray = array($count);
    // Holds current index
    $i = 0;
    // Shuffle multidimensional array
    foreach ($indi as $index)
    {
        $newarray[$i] = $array[$index];
        $i++;
    }
    return $newarray;
}

function email($Name, $Email, $Likes)
{
    $to = $Email;
    $subject = '[Secret Santa] Happy Lolidays from Santabot 2020! Your match is here!';

    $message = "HEY! You are " . $Name ."'s Secret Santa. Isn't that exciting? \r\n\r\nThis is what your match filled in for likes/dislikes: \r\n----------------------------\r\n" . $Likes . "\r\n----------------------------\r\n\r\n\r\nNow get them something nice and thoughtful. We will be swapping sometime around Christmas, so you have a lot of time to put some thought in it.\r\nLet's keep gifts around the $30 mark.\r\n\r\nHappy Lolidays,\r\nDCo's Santabot 2020.\r\n\r\nPS: I have set this up so not even I know the matches nor is a list stored anywhere. DO NOT delete this email if you are at risk of forgetting your match.";

$headers = 'From: Santabot 2020 <santabot2020@mydomain.com>' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
sleep(1000);
}

$con = mysql_connect("mysql.myserver.com", "username", "password") or die(mysql_error());
mysql_select_db("lolidays_dco", $con) or die(mysql_error());
$array;
//I just changed this array size now. Is this the right syntax?
for ($i = 1; $i <= array.length() -1; $i++) {
    $sql = "SELECT * FROM tbl_data WHERE Number = " . $i;
    $result = mysql_query($sql);
    $count=mysql_num_rows($result);
    while($row = mysql_fetch_array($result))
        {
        $Name = $row['Name'];
        $Email = $row['Email'];
        $Likes = $row['Likes'];
        }
    $array[$i] = array("Name" => $Name, "Email" => $Email, "Likes" => $Likes);


}
$array = twodshuffle($array);
$string;
//changed this array length as well, is this the right syntax?
for ($i = 0; $i <= array.length(); $i++) {
    if ($i == 2) {
        $n = $array['0']["Name"];
        $e = $array[$i]["Email"];
        $l = $array['0']["Likes"];
        email($n, $e, $l);
        echo "Email Sent!<br />";
        $string = $string . $array[$i]["Name"] . " => " . $array['0']["Name"] . "\r\n";
        email('Matches', 'backup@email.com', $string);
    }
    else {
        $j = $i + 1;
        $n = $array[$j]["Name"];
        $e = $array[$i]["Email"];
        $l = $array[$j]["Likes"];
        email($n, $e, $l);
        echo "Email Sent!<br />";
        $string = $string . $array[$i]["Name"] . " => " . $array[$j]["Name"] . "\r\n";

    }
}
echo "<strong>Done!</strong>";
?>

您已硬编码收件人:

    $n = $array['0']["Name"];   <---should be $i, not '0'
    $e = $array[$i]["Email"];
    $l = $array['0']["Likes"];   <---should be $i, not '0'
$n=$array['0'][“Name”];