Swiftmailer 收件人 mysql

Swiftmailer destinatarios mysql

我需要用 phpmailer 发送存储在 mysql 数据库中的多封电子邮件,但是当我想执行它时 returns 一个 500 页的错误,我明白问题是当我输入里面的数据:

->setTo(["'".$row['email']."'" => "'".$row['nombre']."'"])

我澄清一切都很完美,只是当我输入任何类型的变量或调用数据库时: -> setTo (["'". $ row ['email']. "'" => "'". $ row [' name ']. "'"]) 它 returns 一个错误。 这是我的完整代码:

<?php 
include ('../db.php');
$query =$db->query("SELECT id, email, status, nombre, enviados FROM 
contactos WHERE email='example@gmail.com' OR 
email='example@icloud.com'");
require_once './vendor/autoload.php';
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.hostinger.com.ar', 
587))
->setUsername('example@example.com')
->setPassword('example')
   ;

 // Create the Mailer using your created Transport
 $mailer = new Swift_Mailer($transport);

 // Create a message
 $message = (new Swift_Message('msm'))
  ->setFrom(['example@example.com' => 'John Doe'])

 $datos_seleccionados = [];
  while($row = mysqli_fetch_array($query))
  {
   ->setTo(["'".$row['email']."'" => "'".$row['nombre']."'"])

   }
   ->setBody('INTENTO')
   ;
   // Send the message
   $result = $mailer->send($message);

我需要的是将多个收件人存储在我的数据库中

<?php 
include ('../db.php');
$query =$db->query("SELECT id, email, status, nombre, enviados FROM 
contactos WHERE email='example@gmail.com' OR 
email='example@icloud.com'");
require_once './vendor/autoload.php';
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.hostinger.com.ar', 
587))
->setUsername('example@example.com')
->setPassword('example')
   ;

 // Create the Mailer using your created Transport
 $mailer = new Swift_Mailer($transport);



 $datos_seleccionados = [];
$toEmailList=[];
  while($row = mysqli_fetch_array($query))
  {
    $toEmailList[$row['email']]=$row['nombre'];

   }
 // Create a message
 $message = (new Swift_Message('msm'))->setFrom(['example@example.com' => 'John Doe'])->setTo($toEmailList)->setBody('INTENTO');
   // Send the message
   $result = $mailer->send($message);

您的代码存在问题,您正在尝试连接键和值。 您必须一次调用所有函数。 谢谢