我需要用phpmailer发送存储在mysql数据库中的多个电子邮件,但当我想执行它时,它会返回一个500页的错误,我知道问题是当我在里面输入数据时:
->setTo(["'".$row['email']."'" => "'".$row['nombre']."'"])我澄清了一切都很完美,只是当我输入任何类型的变量或调用:-> setTo (["'".$ row‘email’。“=>”。$ row‘name’。"'"])它返回一个错误。这是我的完整代码:
<?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);我需要的是将多个收件人存储在我的数据库中
发布于 2019-05-22 22:24:34
<?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);您的代码的问题是您正在尝试连接键和值。你必须一次调用所有函数。谢谢
https://stackoverflow.com/questions/56258979
复制相似问题