Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.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
对于phpmailer消息中的循环?_Php_Html_Phpmailer - Fatal编程技术网

对于phpmailer消息中的循环?

对于phpmailer消息中的循环?,php,html,phpmailer,Php,Html,Phpmailer,我有一个表格,每行显示复选框,用户可以选择多个复选框,然后单击提交,这将使用phpmailer发送电子邮件。 我希望用户选择的项目包含在电子邮件正文中。我知道下面的是错误的,但是有人能告诉我怎么做吗 这就是我目前所拥有的。。。它确实发送电子邮件,但只有数组中的第一个选择在正文中 $select = $_POST['select']; if(empty($select)) { echo("You didn't make any selections."); } else { $count =

我有一个表格,每行显示复选框,用户可以选择多个复选框,然后单击提交,这将使用phpmailer发送电子邮件。 我希望用户选择的项目包含在电子邮件正文中。我知道下面的是错误的,但是有人能告诉我怎么做吗

这就是我目前所拥有的。。。它确实发送电子邮件,但只有数组中的第一个选择在正文中

$select = $_POST['select'];
if(empty($select)) 
{
 echo("You didn't make any selections.");
} 
else
{
$count = count($select);
 for($i=0; $i < $count; $i++)
{

$to = "test@test.com";
$subject = "Booking Reguest";
$message = '    
<html>
<head>
<title>Booking Request</title>
</head>
<body>
<p>Please create bookings for the following ...</p>
<p>'. $select[$i] .',</p>
<p>Kind regards</p>
<p>blah blah blah</p>
</body>
</html>';
$headers = 'From: noreply@test.com' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

mail($to,$subject,$message,$headers);
    }
    }
$select=$\u POST['select'];
if(空($select))
{
echo(“你没有做任何选择。”);
} 
其他的
{
$count=count($select);
对于($i=0;$i<$count;$i++)
{
$to=”test@test.com";
$subject=“预订要求”;
$message='1
预订请求
请为以下内容创建预订

“.$select[$i]”

问候

废话废话

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

谢谢你的帮助

也许您正在循环整个邮件,而不是仅选择

请向我们提供您的HTML代码,但如果我理解了问题,这将解决它:

$select = $_POST['select'];
if(empty($select)) 
{
 echo("You didn't make any selections.");
} 
else
{
$count = count($select);

$to = "test@test.com";
$subject = "Booking Reguest";
$message = '    
<html>
<head>
<title>Booking Request</title>
</head>
<body>
<p>Please create bookings for the following ...</p>
<p>';
 for($i=0; $i < $count; $i++)
{
if ($i == (count($select)-1)) {
$message .= $select[$i];
}
else {
$message .= $select[$i] .", ";
}
};
$message .= '</p>
<p>Kind regards</p>
<p>blah blah blah</p>
</body>
</html>';
$headers = 'From: noreply@test.com' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

mail($to,$subject,$message,$headers);
    }
$select=$\u POST['select'];
if(空($select))
{
echo(“你没有做任何选择。”);
} 
其他的
{
$count=count($select);
$to=”test@test.com";
$subject=“预订要求”;
$message='1
预订请求
请为以下内容创建预订

",; 对于($i=0;$i<$count;$i++) { 如果($i==(计数($select)-1)){ $message.=$select[$i]; } 否则{ $message.=$select[$i]。“,”; } }; $message.='

问候

废话废话

'; $headers='来自:noreply@test.com“。”\r\n”; $headers.='MIME版本:1.0'。“\r\n”; $headers.=“内容类型:text/html;字符集=iso-8859-1”。“\r\n”; 邮件($to、$subject、$message、$headers); }
通过这种方式,它将在复选框元素之间放置一个逗号,忽略最后一个逗号

希望这有帮助

编辑:

另外,您在每个
之后都缺少一些

标记,是吗?这样,您将收到带有内联文本的电子邮件