我在将电子邮件仅发送到值数组中的第一个值时遇到问题。请检查以下代码,请帮忙。
$ categoria = 12;
数据库中的订阅值:
12
30,12
11,24,12,30
27,11
$subscriptors=get_result("SELECT email, subscription FROM {$TABLE_PREFIX}users WHERE subscription IS NOT NULL",true);
if (count($subscriptors)>0)
{
$bcc=array();
$ne=0;
include(load_language("lang_usercp.php"));
for ($i=0;$i<count($subscriptors);$i++)
{
if (in_array($categoria, explode(",",$subscriptors[$i]["subscription"])))
{
$bcc[]=$subscriptors[$i]["email"];
$ne++;
if ($ne>49)
send_mail($SITEEMAIL,$language["SUB_SUBJECT"],sprintf($language["SUB_EMAIL"],$filename, "$BASEURL/index.php?page=torrent-details&id=$hash","$BASEURL/download.php?id=$hash&f=" . urlencode($filename) . ".torrent"),false,array(),$bcc);
}
}
send_mail($SITEEMAIL,$language["SUB_SUBJECT"],sprintf($language["SUB_EMAIL"],$filename, "$BASEURL/index.php?page=torrent-details&id=$hash","$BASEURL/download.php?id=$hash&f=" . urlencode($filename) . ".torrent"),false,array(),$bcc);
}
据我了解,$ bcc是电子邮件的数组。但是send_mail函数仅将邮件发送到数组的第一个值。而且此问题仅在SMTP上。
随后发送邮件功能
function send_mail($rec_email,$subject,$message, $IsHtml=false, $cc=array(), $bcc=array()) {
global $THIS_BASEPATH, $btit_settings;
// if (!method_exists('PHPMailer','IsMail'))
include($THIS_BASEPATH.'/phpmailer/class.phpmailer.php');
$mail=new PHPMailer();
if ($btit_settings['mail_type']=='php') {
$mail->IsMail(); # send via mail
if (!empty($cc))
$mail->AddCustomHeader('Cc: '.implode(',',$cc));
if (!empty($bcc))
$mail->AddCustomHeader('Bcc: '.implode(',',$bcc));
} else {
$mail->IsSMTP(); # send via SMTP
$mail->Host = $btit_settings['smtp_server']; # SMTP servers
$mail->Port = $btit_settings['smtp_port']; # SMTP port
$mail->SMTPAuth = true; # turn on SMTP authentication
$mail->Username = $btit_settings['smtp_username']; # SMTP username
$mail->Password = $btit_settings['smtp_password']; # SMTP password
if (!empty($cc))
foreach($cc as $carbon_copy)
$mail->AddCC($carbon_copy[0],$carbon_copy[0]);
if (!empty($bcc))
foreach($bcc as $blind_carbon_copy)
$mail->AddBCC($blind_carbon_copy[0],$blind_carbon_copy[0]);
}
$mail->From = $btit_settings['email'];
$mail->FromName = $btit_settings['name'];
$mail->CharSet = $btit_settings['default_charset'];
$mail->IsHTML($IsHtml);
$mail->AddAddress($rec_email);
$mail->AddReplyTo($btit_settings['email'],$btit_settings['name']);
$mail->Subject = $subject;
$mail->Body = $message;
return ($mail->Send())?true:$mail->ErrorInfo;
}
答案 0 :(得分:0)
问题是AddBCC和AddCC。两者都不起作用。
以下行已替换
foreach ($cc as $carbon_copy)
$mail->AddCC($carbon_copy, $carbon_copy);
foreach ($bcc as $blind_carbon_copy) {
$mail->AddBCC($blind_carbon_copy, $blind_carbon_copy);
使用
$mail->AddCustomHeader('Cc: '.implode(',',$cc));
$mail->AddCustomHeader('Bcc: '.implode(',',$bcc));