Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.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
Php电子邮件Mysql获取数组_Php_Mysql_Email_Variables - Fatal编程技术网

Php电子邮件Mysql获取数组

Php电子邮件Mysql获取数组,php,mysql,email,variables,Php,Mysql,Email,Variables,我用这个脚本发送一封包含我数据库信息的电子邮件。用户在数据库中可以有1+个项目及其位置。因此,当我清空与用户匹配的行时,发送的电子邮件数量等于它们拥有的行数。因此,如果他们在数据库中有8个项目,它会发送8封电子邮件。每个添加一个项目。第一封邮件有一个条目,第二封邮件有两个条目,依此类推。我正试图找到一个简单的方法,使其在发送电子邮件之前获得所有信息,以便客户只收到一封电子邮件。合乎逻辑的方法是回显信息,但我不能使用php变量。我没有在下面的代码中包含查询和数据库连接。任何帮助都会被爱 while

我用这个脚本发送一封包含我数据库信息的电子邮件。用户在数据库中可以有1+个项目及其位置。因此,当我清空与用户匹配的行时,发送的电子邮件数量等于它们拥有的行数。因此,如果他们在数据库中有8个项目,它会发送8封电子邮件。每个添加一个项目。第一封邮件有一个条目,第二封邮件有两个条目,依此类推。我正试图找到一个简单的方法,使其在发送电子邮件之前获得所有信息,以便客户只收到一封电子邮件。合乎逻辑的方法是回显信息,但我不能使用php变量。我没有在下面的代码中包含查询和数据库连接。任何帮助都会被爱

while ($row = mysql_fetch_array($query)) {
$Items .=  $row['Items']. " - Aisle " .$row['Loc']. "<p>&nbsp;</p>";
$to = "example@example.com";
$from = "example@example.com";
$subject = "Test";
$message = "$Items";
$headers = "MIME-Version: 1.0 \r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
$headers .= "From: example@example.com";
mail($to, $subject, $message, $headers);
}
while($row=mysql\u fetch\u array($query)){
$Items.=$row['Items']。“-过道“$row['Loc']。”

”; $to=”example@example.com"; $from=”example@example.com"; $subject=“Test”; $message=“$Items”; $headers=“MIME版本:1.0\r\n”; $headers.=“内容类型:text/html;字符集=iso-8859-1\r\n”; $headers.=”来自:example@example.com"; 邮件($to、$subject、$message、$headers); }
当您迭代这些项目时,您应该只生成一条消息,而不是整个电子邮件。。在不了解更多查询的情况下,很难做更多的事情。不管怎样,我还是要试一试:

$message = '';

while ($row = mysql_fetch_array($query)) {
     $Items =  $row['Items']. " - Aisle " .$row['Loc']. "<p>&nbsp;</p>";
     $message .= "$Items";
}

$headers = "MIME-Version: 1.0 \r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
$headers .= "From: example@example.com";
mail($to, $subject, $message, $headers);
$message='';
while($row=mysql\u fetch\u array($query)){
$Items=$row['Items']。“-过道“$row['Loc']。”

”; $message.=“$Items”; } $headers=“MIME版本:1.0\r\n”; $headers.=“内容类型:text/html;字符集=iso-8859-1\r\n”; $headers.=”来自:example@example.com"; 邮件($to、$subject、$message、$headers);

注意:我不会按原样实现此代码。这是一个如何构造代码的示例。

只需将发送函数移出循环即可:

while ($row = mysql_fetch_array($query)) {
     $Items .=  $row['Items']. " - Aisle " .$row['Loc']. "<p>&nbsp;</p>";

 }
 if ($Items != '') {
      $to = "example@example.com";
      $from = "example@example.com";
      $subject = "Test";
      $message = "$Items";
      $headers = "MIME-Version: 1.0 \r\n";
      $headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
      $headers .= "From: example@example.com";
      mail($to, $subject, $message, $headers);
 }
while($row=mysql\u fetch\u array($query)){
$Items.=$row['Items']。“-过道“$row['Loc']。”

”; } 如果($Items!=''){ $to=”example@example.com"; $from=”example@example.com"; $subject=“Test”; $message=“$Items”; $headers=“MIME版本:1.0\r\n”; $headers.=“内容类型:text/html;字符集=iso-8859-1\r\n”; $headers.=”来自:example@example.com"; 邮件($to、$subject、$message、$headers); }
您的
串联
错误,应首先在循环外将变量声明为空

$Items = '';
然后启动
循环
,获取连接变量所需的所有数据

while ($row = mysql_fetch_array($query)) 
{
    $Items .=  $row['Items']. " - Aisle " .$row['Loc']. "<p>&nbsp;</p>";
}

然后我希望您记住,
mysql.*
函数已被弃用,因此我建议您切换到或

为什么将
$Items
连接在一起?不带“.”它只发送数据库中的一个项。似乎必须包含点才能发送多个项目。多亏了尤金,我也明白了。感谢所有回复帮助的人。你应该以一个普通的相等值开始,然后连接起来,否则它将无法正常工作。我很感谢你的帮助。@BobStone你应该把答案标记为正确,然后给他一个代表。
$Items = '';
while ($row = mysql_fetch_array($query)) 
{
    $Items .=  $row['Items']. " - Aisle " .$row['Loc']. "<p>&nbsp;</p>";
}
$from = "example@example.com";
$subject = "Test";
$message = "$Items";
$headers = "MIME-Version: 1.0 \r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
$headers .= "From: example@example.com";
mail($to, $subject, $message, $headers);