deh*_*len 0 php mysql arrays email implode
我有一个PHP脚本,应该发送邮件给多个收件人.我想把所有收件人都写到BCC.电子邮件地址是从mysql数据库中检索的.不幸的是它不会发送任何邮件.
这是脚本:
<?php
include("/path/to/config.php");
$db = @new mysqli($mysql_host, $mysql_user, $mysql_pass, $mysql_db);
if (mysqli_connect_errno()) {
die ('Konnte keine Verbindung zur Datenbank aufbauen: '.mysqli_connect_error().'('.mysqli_connect_errno().')');
}
$sql = "select email from newsletter";
$recipients = array();
$result = $db->query($sql);
if (!$result) {
printf("Query failed: %s\n", $mysqli->error);
exit;
}
while($row = $result->fetch_row()) {
$recipients[]=$row;
}
print_r($recipients);
$result->close();
$db->close();
$to = 'myemail';
$subject = $_POST["subject"];
$body = $_POST["message"];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'Reply-To: support@mymail.de' . "\r\n";
$headers .= 'BCC: ' . implode(', ', $recipients) . "\r\n";
mail($to, $subject, $body, $headers);
?>
Run Code Online (Sandbox Code Playgroud)
print_r返回有效的响应:
Array ( [0] => Array ( [0] => first@mail.com ) [1] => Array ( [0] => second@mail.com ) )
Run Code Online (Sandbox Code Playgroud)
你正在制作一个数组数组:
while($row = $result->fetch_row()) {
^^^^---array
$recipients[]=$row;
^^^^---add array to another array
}
Run Code Online (Sandbox Code Playgroud)
你可能想要这样的东西
while($row = ...) {
$recipients[] = $row[0];
}
Run Code Online (Sandbox Code Playgroud)
所以你要添加JUST电子邮件地址.
既然你正在使用数组数组,并将结果字符串填充到另一个字符串中,那么你将会真正得到 BCC: Array, Array, Array, ....
| 归档时间: |
|
| 查看次数: |
117 次 |
| 最近记录: |