我正在努力将电子邮件批量发送到来自数据库的电子邮件列表。然而,当发送电子邮件时,它们不是动态的,即对于每个用户都是相同的,有人可以告诉我我做错了,请谢谢。
web.php
Route::post('/sendmail', function (\Illuminate\Http\Request $request,
\Illuminate\Mail\Mailer $mailer) {
$x = 1;
while($x <= 10) {
$db = new PDO("mysql:dbname=website4.0;host=localhost", "root", "");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = ("SELECT name, email FROM students WHERE studentID=$x");
$statement = $db->prepare($query);
$statement->execute();
$values = $statement->fetchAll();
$mailer
->to($values)
->send(new \App\Mail\Mymail($request->input('title')));
$x++;
}
return redirect()->back();
})-> name('sendmail');
<?php
这是模板,因此对于id = 1,它需要获取id 1的名称并在电子邮件atm中发布它只向所有电子邮件发送id模板,以便将具有特定模板的单个模板发送给用户名。
mymail.php
$db = new PDO("mysql:dbname=website4.0;host=localhost", "root", "");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = ("SELECT title, date, address, intro, mainbody, paragraph, footer
FROM template");
$statement = $db->prepare($query);
$statement->execute();
$values = $statement->fetchAll();
foreach($values as $row){
$row["title"];
$row["date"];
$row['address'];
$row["intro"];
$row["mainbody"];
$row["paragraph"];
$row["footer"];
}
echo '<h1>'.$row["title"]. '</h1>';
echo '<p>' .$row["date"]. '</p>';
echo $row["address"];
$db = new PDO("mysql:dbname=website4.0;host=localhost", "root", "");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = ("SELECT name FROM students where studentID=1");
$statement = $db->prepare($query);
$statement->execute();
$values = $statement->fetchAll();
foreach($values as $row){
$row["name"];
echo $row["name"];
}