$email_ids= DB::table('users')->pluck('email_id');
$name = DB::table('users')-> pluck('name');
foreach ($email_ids as $email_id ) {
Mail::send('mail', ['user' => $name ] , function ($message) use ($email_id) {
$message->from('abc@xyz.com', 'ABC');
$message->to($email_id)->subject("Welcome");
});
}
我想通过电子邮件向各个用户发送邮件。我在数组中得到$email_ids
和$name
。但是当我运行此代码时,我收到错误
htmlentities()期望参数1为字符串,给定数组
当我用'user' => $name
替换'user' => $email_id
时。我跑得很成功。
当我发送邮件时,它应该像
Hello , $name(name of user)
谢谢
答案 0 :(得分:2)
您的代码应该是: -
$users = DB::table('users')->get(); // get all users
foreach ($users as $user ) {
$name = $user->name; // get user's name
$email_id = $user->email_id; // get user's email
Mail::send('mail', ['user' => $name ] , function ($message) use ($email_id) {
$message->from('abc@xyz.com', 'ABC');
$message->to($email_id)->subject("Welcome");
});
}
注意: - 您可以通过以下查询从数据库表中获取特定列,
$users = DB::table('users')->select('name', 'email_id')->get();
答案 1 :(得分:0)
当视图文件中出现错误时,Laravel会显示htmlentities()错误。
在您的情况下,您将在不同的阵列中获取姓名和电子邮件,但您只能预告 public void attendence() throws SQLException{
employeelist = FXCollections.observableArrayList();
ename.setCellValueFactory(new PropertyValueFactory<Employee,String>("ename"));
ecnic.setCellValueFactory(new PropertyValueFactory<Employee,String>("ecnic"));
ebalance.setCellValueFactory(new PropertyValueFactory<Employee,Double>("ebalance"));
etotalpaid.setCellValueFactory(new PropertyValueFactory<Employee,Double>("etotalpaid"));
estatus.setCellValueFactory(new PropertyValueFactory<Employee,String>("estatus"));
estatus.setCellFactory(ComboBoxTableCell.forTableColumn(new DefaultStringConverter(), attendenceoptions));
estatus.setOnEditCommit(
new EventHandler<CellEditEvent<Employee, String>>() {
@Override
public void handle(CellEditEvent<Employee, String> t) {
((Employee) t.getTableView().getItems().get(t.getTablePosition().getRow())).setEstatus(t.getNewValue());
};
});
estatus.setEditable(true);
stmt = conn.createStatement();
sql = "select * from employe";
rs = stmt.executeQuery(sql);
while(rs.next()){
employeelist.add(new Employee(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getDouble(5),rs.getDouble(6),"Present"));
employeetable.setItems(employeelist);
}
stmt.close();
rs.close();
}
}
而不是$email_ids
此行
$name
此Mail::send('mail', ['user' => $name ] , function ($message) use ($email_id) {
中的是按查询返回的名称数组,您将其打印为字符串,这就是为什么它会发出错误。
要实现您想要的更改代码
$name