gpt4 book ai didi

php - 无法让此自动电子邮件在 php 中工作。你能帮助我吗?

转载 作者:行者123 更新时间:2023-11-29 14:11:48 24 4
gpt4 key购买 nike

我正在尝试制作这个 secret 的圣诞老人自动电子邮件脚本,这真的让我感到困惑......它无法正确发送电子邮件(一个人收到大量电子邮件,其他人没有收到任何......)

我尝试只更改 for 循环中数组的长度,我做对了吗?

我使用了随机播放功能和电子邮件功能,它们似乎工作得很好(除了电子邮件功能上的 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'

关于php - 无法让此自动电子邮件在 php 中工作。你能帮助我吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13385487/

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