php - Swiftmailer 目的地 mysql

标签 php mysql email swiftmailer

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

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

我澄清,一切都很完美,只有当我输入任何类型的变量或调用以下内容中的数据库时: -> setTo(["'".$row['电子邮件']."'"=> "'".$row['姓名']. “'”]) 它返回一个错误。 这是我的完整代码:

<?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);

您的代码的问题是您正在尝试连接键和值。 您必须立即调用所有函数。 谢谢

关于php - Swiftmailer 目的地 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56258979/

相关文章:

PHP 日志 : Warning format

javascript - Sql 未在 UPDATE 上设置值

python - 使用 Python 下载/解析电子邮件

php - 使表格在排序时显示交替的颜色背景

php - 这是以类方式或 OOP 访问 mysql 的正确方法吗?

MySQL:从带有锁的另一个表创建一个表

php - 查找下次营业时间; mysql小时计算

php - 如何将在php中创建的变量传递给mysql数据库?

c# - 如何从 Windows CE 设备 (Compact Framework) 发送电子邮件?

python - 如何从 Python 发送 header 中包含姓名的电子邮件