【发布时间】:2024-04-29 00:55:01
【问题描述】:
我的数据库中有 2 个表,我进行了查询以验证两个表中是否不存在电子邮件地址,列出所有用户,现在电子邮件是我用来验证用户是否唯一的电子邮件。我运行了我的脚本,它运行良好,我做了一个回显,我得到了 10 次迭代(10 个不同的用户,电子邮件不重复)。现在我需要为每次迭代发送一封电子邮件,问题是当我添加我的邮件功能时,我只收到 1 个用户并且只发送了 1 个 emai,错过了 9 个用户。我怎样才能完成 10 个用户,每个用户 10 封电子邮件。
<?php
include 'myDB.php';
$sql = " query works fine ";
$result = mysqli_query($conn, $sql);
//var_dump($result);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
foreach ($row as $key => $gtm) {
$message .= $gtm;
$header ="From: no-reply@testme.com" . "\r\n";
$para = 'web2@tesy.com';
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$titulo = 'Mailing list Newsletter';
$message = '<html><body>';
$message .= '<br/> <p>El siguiente usuario abandono el la compra de un paquete en booking hello </p><br/>';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="2">';
$message .= "<tr><td><strong>Nombre del paquete:</strong> </td><td>" . $row["nombre_del_paquete"]."</td></tr>";
$message .= "<tr><td><strong>Precio Total del paquete:</strong> </td><td>". $row["precio_total"]."</td></tr>";
$message .= "<tr><td><strong>Nombre:</strong> </td><td>" . $row["nombre"]. "</td></tr>";
$message .= "<tr><td><strong>Apellido:</strong> </td><td>" . $row["apellido"]."</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . $row["email"]. "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
if(mail($para, $titulo, $message, $header)){
echo "recorded successfully";
die();
}else{
echo "false";
}
}
}
} else {
echo "0 results";
}
?>
现在当我添加邮件功能时,我只获得 1 个用户(第 1 个),如果我删除邮件功能并执行回显,我会获得所有用户(10)
【问题讨论】:
-
请清理你的代码
-
您仅将其发送到一个电子邮件地址,在 $header 中使用 $row["email"],例如 $header ="To: " 。 $row["email"] 。 "\r\n";