複数アドレス($addressの配列)をforeach の$mail->addBCC($value);で回せばOKですね。
$mail->addAddress(”);、$mail->addCC(”);は使わなければ、コメントアウトします。
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require 'vendor/autoload.php'; $address = array('target1@gmail.com','target2@hotmail.com','target3@yahoo.co.jp'); $mail = new PHPMailer(true); try{ $mail->SMTPDebug = 2; $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = 'fromhoge@gmail.com'; $mail->Password = 'app pass'; $mail->SMTPSecure = 'tls'; $mail->Port = 587; $mail->setFrom('fromhoge@gmail.com'); // $mail->addAddress(''); // $mail->addCC(''); foreach($address as $value){ $mail->addBCC($value); } $mail->addAttachment('test.gif'); $mail->isHTML(true); $mail->Subject = 'Here we comes!'; $mail->Body = 'This is the HTML message body <b>in bold</b>'; $mail->AltBody = 'This is the body in plain text for non-HTML'; $mail->send(); echo 'messeage has been sent'; } catch (Exception $e){ echo "Message could not be send, Mailer Error:", $mail->ErrorInfo; }
BCCで問題なく届いてます。これは想像以上だな~