我需要使用 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/