在Laravel 5
我尝试使用以下路线为用户发送邮件:
Route::post('/sendEmailToUser', array(
'as' => 'sendEmailToUser', function () {
$data = \App\User::find(Request::input('user_id'));
$cdata = array('message' => Request::input('message'), 'email' => $data->email);
Mail::send('emails.custom_email_to_user', $cdata, function ($message) use ($data) {
$message->to($data['email'], 'Sample')->subject('Sample');
});
if (count(Mail::failures()) > 0) {
Log::emergency("email dont send to user");
return 0;
} else {
Log::info("email successfull send to user id" + Request::input('user_id'));
return 1;
}
}
));
结果$cdata
是:
Array
(
[message] => this is test mail
[email] => myname@server.com
)
不幸的是我收到了这个错误:
htmlentities() expects parameter 1 to be string, object given (View: D:\xampp\htdocs\epay-pro\resources\views\emails\custom_email_to_user.blade.php)
我的简单电子邮件页面是:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
</head>
<body>
<h2>Sample</h2>
<div>
{{$message}}
{{ URL::to('www.epay.li') }}<br/>
</div>
</body>
</html>