我想发送多封不同内容的电子邮件。为此,用户需要选中复选框并单击一个按钮以发送选中的所有电子邮件。
为此,我有一个表格来显示数据库中的内容。
select nomeUser,email,nomeVoucher,categoria,preco,confirmacao,fileName,filePDF
from historico
Where confirmacao = 'a confirmar'
LIMIT $start, $per_page";
$stmt = $mybd->prepare($query);
$stmt->execute();
$stmt->bind_result($nomeUser,$email,$nomeVoucher,$categoria,$preco,$confirmacao,$file2,$filePDF);
while($stmt->fetch()){ ?>
<tbody>
<tr><td><?php echo $nomeUser ?></td>
<td><?php echo $email ?></td>
<td><?php echo $nomeVoucher ?></td>
<td><?php echo $categoria ?></td>
<td><?php echo $preco ?></td>
<td><?php echo $confirmacao ?></td>
<?php $current = file_get_contents($file2,$filePDF); ?>
<td style='display:none;'><?php echo $current ?></td>
<td style='display:none;'><?php echo $file2 ?></td>
<td><INPUT TYPE='checkbox' NAME='mail[]' VALUE='1'></td>
</tr>
</tbody>
<?php }$stmt->close();
发送它的代码是:
if(isset($_POST['enviar'])){
$mails = $_POST['mail'];
if(count($mails) > 0){
for($i=0;$i<count($mails);$i++){
$fromname[$i] = "Compra do Voucher";
$from[$i] = "jonathan@tribanet.com";
$subject[$i] = "Compra do Voucher";
$message = "O seu pagamento foi verificado com sucesso!" . "\r\n" .
"Por favor, verifica se o voucher pedido é o sucedido: " . "\r\n" .
"Categoria: $categoria[$i] \r\n" .
"Nome do Voucher: $nomeVoucher[$i] \r\n" .
"Preço: $preco[$i] € \r\n" .
"O seu voucher está disponível aqui $nomeVoucher[$i] \r\r\n" .
"Equipa do Voucher \r\n";
$new_array=array($email[$i]);
$newstring=implode(",",$new_array);
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.sapo.pt";
$mail->Username = "jonitopsg@sapo.pt";
$mail->Password = "200886";
$mail->Port = 25;
$mail->Sender = "$from[$i]";
$mail->FromName = "$fromname[$i]";
$mail->Subject = "$subject[$i]";
$mail->Body = "$message";
$mail->CharSet="utf-8";
$mail->AddStringAttachment($current[$i],$file2[$i]);
$mail->AddAddress($newstring,$nomeUser[$i]);
if ($mail->send()){
return true;
}else
return $mail->ErrorInfo;
$mail->ClearAddresses();
$mail->ClearAttachments();
}
}
}
它显示错误:“地址无效:您必须提供至少一个收件人电子邮件地址。” 我做错了什么?谢谢