我通过查询从数据库中获取两个电子邮件ID。两者都存储在一个变量中。我想通过PHPMailer将这些地址发送到这两个地址,并将它们保存在cc中。目前只有一个电子邮件被选中并以cc传递。我能知道我哪里出错了。我的代码在这里,
$get_cc_email_id_sql=mysql_query("select * from tbl_name where column_name IN(13,5)");
$user_email_cc='';
while ($get_data_cc=mysql_fetch_array($get_cc_email_id_sql))
{
$user_email_cc=$get_data_cc['email'];
}
$mail = new PHPMailer();
$subject = "Mail";
$content ="XYZ";
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "ssl";
$mail->Debugoutput = 'html';
$mail->Port = 465;
$mail->Username = "xyz@xyz.com"; // Changed username and password from
$mail->Password = "xyz";
$mail->Host = "ssl://smtp.xyz.com";
$mail->Mailer = "smtp";
$mail->SetFrom("xyz@xyz.com", "XYZ");
$mail->AddAddress(abc@abc.com);
$mail->AddCC($user_email_cc);
$mail->Subject = $subject;
$mail->WordWrap = 80;
$mail->MsgHTML($content);
$mail->IsHTML(true);
if(!$mail->Send())
echo "Problem sending mail.";
else
echo "Mail Sent";
答案 0 :(得分:2)
使用此代码
$mail->AddCC('person1@domain.com', 'Person One');
$mail->AddCC('person2@domain.com', 'Person Two');
答案 1 :(得分:1)
使用$user_email_cc
作为数组,然后它会存储两个电子邮件0 and 1
位置
$user_email_cc=array();
while ($get_data_cc=mysql_fetch_array($get_cc_email_id_sql))
{
$user_email_cc[] =$get_data_cc['email'];
}
新代码
$get_cc_email_id_sql=mysql_query("select * from tbl_name where column_name IN(13,5)");
$user_email_cc=array();
while ($get_data_cc=mysql_fetch_array($get_cc_email_id_sql))
{
$user_email_cc[] =$get_data_cc['email'];
}
$mail = new PHPMailer();
$subject = "Mail";
$content ="XYZ";
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "ssl";
$mail->Debugoutput = 'html';
$mail->Port = 465;
$mail->Username = "xyz@xyz.com"; // Changed username and password from
$mail->Password = "xyz";
$mail->Host = "ssl://smtp.xyz.com";
$mail->Mailer = "smtp";
$mail->SetFrom("xyz@xyz.com", "XYZ");
foreach($user_email_cc as $email_cc){
$mail->AddCC($email_cc);
}
$mail->AddAddress(abc@abc.com);
$mail->Subject = $subject;
$mail->WordWrap = 80;
$mail->MsgHTML($content);
$mail->IsHTML(true);
if(!$mail->Send())
echo "Problem sending mail.";
else
echo "Mail Sent";
答案 2 :(得分:0)
您可以多次拨打$mail->AddCC(...)
,就像$mail->AddAddress(...)
?