首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swiftmailer目标mysql

Swiftmailer目标mysql
EN

Stack Overflow用户
提问于 2019-05-22 22:18:28
回答 1查看 31关注 0票数 0

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

代码语言:javascript
复制
->setTo(["'".$row['email']."'" => "'".$row['nombre']."'"])

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

代码语言:javascript
复制
<?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);

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-22 22:24:34

代码语言:javascript
复制
<?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);

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56258979

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档