[英]send an email for each result of mysql query in php
i have a 2 tables in my db, i did a query to verify if the email address is not present in both tables, list all users, now the email is what i use to verify that user is unique. 我在数据库中有2个表,我做了一个查询以验证两个表中都不存在该电子邮件地址,列出所有用户,现在使用该电子邮件来验证该用户是否唯一。 i ran my script and it works perfect, i do an echo and i get 10 iterations (10 diferent users that email is not duplicated).
我运行了我的脚本,它运行良好,执行了回显,并且得到了10次迭代(10个不同的用户未重复发送电子邮件)。 now i need to send an email for each iteration, the issue is that when i add my mail fucntion i'm only receiving the 1 user and only 1 emai is sent, missing out 9 users more.
现在,我需要为每次迭代发送一封电子邮件,问题是,当我添加邮件功能时,我只接收到1个用户,并且仅发送了1个emai,从而丢失了9个用户。 how can i accomplish 10 users, 10 emails one for each user.
我如何才能完成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";
}
?>
now when i added the mail fucntion is when i get 1 user only(the 1 one), if i remove mail function and do an echo i do get all users(10) 现在,当我添加邮件功能时,是仅获得1个用户(第1个用户),如果我删除邮件功能并执行回显操作,我确实会获得所有用户(10个)
remove the die()
: 删除
die()
:
foreach ($row as $key => $gtm) {
// more cod here:
// your problem is in this if:
if(mail($para, $titulo, $message, $header)){
echo "recorded successfully";
// die(); this stops the execution
}else{
echo "false";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.