[英]php array and mysql syntax error
我正在尝试SwiftMailer将电子邮件地址提取到array()
我有一个原始示例,我知道我想在其中放入什么,但是我从树上看不到森林……任何人都可以用适当的眼睛观看请:
// Send the message
$result = $mailer->send($message);
// Send the message
$failedRecipients = array();
$numSent = 0;
这是我在努力的地方:
foreach($groups as $value)
{
echo "<h3>".$value."</h3>"; //this is working
// get the email groups
$sql="SELECT * FROM emails WHERE sendesstat=1 AND deleted=0 AND classhoz=\"".$value."\"";
$query=mysql_query($sql);
// fetch the emails from the group
while($data=mysql_fetch_array($query))
{
$emil="'".$data["email"]."' => '".$data["firstname"]." ".$data["surname"]."'";
echo $emil;
该echo
有效,但我不能放入$to[]
数组...(对不起),这应该是这样的:
$to = array('receiver@domain.org', 'other@domain.org' => 'A name');
问题是given name => 'A name'
我生病了,找不到语法!
$to[ ]= $emil;
}
}
foreach ($to as $address => $name)
{
if (is_int($address)) {
$message->setTo($name);
} else {
$message->setTo(array($address => $name));
}
$numSent += $mailer->send($message, $failedRecipients);
}
printf("Sent %d messages\n", $numSent);
请请其他所有东西现在都在工作,只是缺少这一点。 谢谢
您正在错误地定义$to
数组。
使用它在数组上添加一个项目
$to[$data["email"]] = $data["firstname"]." ".$data["surname"];
// ^ Index ^ Value
稍后,当您使用foreach
循环时,它将完全按照您的方式区分为$ address和$ name。
foreach ($to as $address => $name) {
echo $address;
echo $name;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.