我有一个情况。
我是编程的初学者。我想根据$ to array列表向用户发送电子邮件。如果$ to具有类似的数组元素,那么所有数据都将发送给一个用户。但是如果$ to有不同的元素,那么数据将被发送到$ to数组的不同元素,并带有$ to特定数据。
请帮帮我。
下面是代码: - 我有一个$ to的数组。我需要根据$ to中唯一元素的数量来分隔电子邮件。
if ($category!="Tool"){
$accessEmailBody = "\n<p>Please provide $reqFName $reqLName ($reqWinID) access to the following as per attached approval: </p>\n<blockquote>";
$accessEmailBody = "<p>Hello $displayname ,</p>$accessEmailBody\n\t<ul>";
foreach (array_values($wgs) as $wg) {
list($wgName, $wgCategory, $wgId) = $wg;
if ($to == ''){
$to = $current->getWgEmailByCatID($wgCategory);
}
$accessEmailBody .= "<li>";
$accessEmailBody .= "(". trim($current->getWgCateNameById($wgCategory)). ")";
$accessEmailBody .= " $wgName</li>
<ul>";
$rows = $current->getWgDetails($wgId);
while ($line = mssql_fetch_row($rows)){
$accessEmailBody .= "<li><b>".$current->getWgResourceType($line[0]).":</b> $line[1]</li>";
}
$accessEmailBody .="</ul>";
}
$accessEmailBody .= "\n\t</ul>";
$accessEmailBody .= "\n</blockquote>\n<p>Thank you.<br/>CRALT Admin</p>\n".$body;
if (isset($to)){
return mail($to, $subject, $accessEmailBody, $header);
} else {
return 0;
}
}
答案 0 :(得分:0)
这是我认为你需要的基本概要。显然你需要填写电子邮件功能本身的其他字段......
$to_array = array('john', 'jeff', 'frank', 'bill', 'frank');
$uniqueElems = array();
// this loop will make a new array of unique elements
foreach($to_array as $original_elem){
if ( ! in_array($original_elem, $uniqueElems)) {
$uniqueElems[] = $original_elem;
}
}
// now loop through the array of unique addresses and send them an email
foreach($uniqueElems as $addr){
mail($addr,$subject,$message,$headers,$parameters);
}