我目前正在使用Laravel 5,但任何建议都将不胜感激。我目前正在使用laravel的表单构建器,并且我不断收到此html实体错误。我甚至尝试将textarea更改为文本字段,而且更多都无济于事。下面是我的完整堆栈跟踪。
ErrorException in helpers.php line 455:
htmlentities() expects parameter 1 to be string, object given (View: /home/fujita/resources/views/emails/contact.blade.php)
in helpers.php line 455
at CompilerEngine->handleViewException(object(ErrorException), '1') in PhpEngine.php line 43
at PhpEngine->evaluatePath('/home/fujita/storage/framework/views/e0d450cfe03e94c1d8bac332b837ce79', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'name' => 'jkj', 'email' => 'jkjkjk@m.com', 'phone' => 'jkjkjk', 'message' => object(Message))) in CompilerEngine.php line 57
at CompilerEngine->get('/home/fujita/resources/views/emails/contact.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'name' => 'jkj', 'email' => 'jkjkjk@m.com', 'phone' => 'jkjkjk', 'message' => object(Message))) in View.php line 136
at View->getContents() in View.php line 104
at View->renderContents() in View.php line 78
at View->render() in Mailer.php line 425
at Mailer->getView('emails.contact', array('name' => 'jkj', 'email' => 'jkjkjk@m.com', 'phone' => 'jkjkjk', 'message' => object(Message))) in Mailer.php line 288
at Mailer->addContent(object(Message), 'emails.contact', null, null, array('name' => 'jkj', 'email' => 'jkjkjk@m.com', 'phone' => 'jkjkjk', 'message' => object(Message))) in Mailer.php line 162
at Mailer->send('emails.contact', array('name' => 'jkj', 'email' => 'jkjkjk@m.com', 'phone' => 'jkjkjk', 'message' => 'jkjkj'), object(Closure)) in Facade.php line 216
at Facade::__callStatic('send', array('emails.contact', array('name' => 'jkj', 'email' => 'jkjkjk@m.com', 'phone' => 'jkjkjk', 'message' => 'jkjkj'), object(Closure))) in PagesController.php line 37
at Mail::send('emails.contact', array('name' => 'jkj', 'email' => 'jkjkjk@m.com', 'phone' => 'jkjkjk', 'message' => 'jkjkj'), object(Closure)) in PagesController.php line 37
at PagesController->store(object(ContactFormRequest))
at call_user_func_array(array(object(PagesController), 'store'), array(object(ContactFormRequest))) in Controller.php line 246
at Controller->callAction('store', array(object(ContactFormRequest))) in ControllerDispatcher.php line 162
at ControllerDispatcher->call(object(PagesController), object(Route), 'store') in ControllerDispatcher.php line 107
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 108
at ControllerDispatcher->callWithinStack(object(PagesController), object(Route), object(Request), 'store') in ControllerDispatcher.php line 67
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\PagesController', 'store') in Route.php line 198
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 131
at Route->run(object(Request)) in Router.php line 691
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Router.php line 693
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 660
at Router->dispatchToRoute(object(Request)) in Router.php line 618
at Router->dispatch(object(Request)) in Kernel.php line 210
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 111
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53
<p>
Name: {{ $name }}
</p>
<p>
{{ $email }}
</p>
<p>
{{ $phone }}
</p>
<p>
{{ $message }}
</p>
<?php namespace App\Http\Requests;
use App\Http\Requests\Request;
class ContactFormRequest extends Request {
public function authorize()
{
return true;
}
public function rules()
{
return [
'name' => 'required',
'email' => 'required|email',
'phone' => 'required',
'message' => 'required',
];
}
}
{!! Form::open(array('route' => 'contact_store', 'class' => 'form')) !!}
<div class="form-group">
{!! Form::text('name', null,
array('required',
'class'=>'form-control',
'placeholder'=>'Name*')) !!}
</div>
<div class="form-group">
{!! Form::text('email', null,
array('required',
'class'=>'form-control',
'placeholder'=>'Email Address*')) !!}
</div>
<div class="form-group">
{!! Form::text('phone', null,
array('required',
'class'=>'form-control',
'placeholder'=>'Phone')) !!}
</div>
<div class="form-group">
{!! Form::textarea('message', null,
array('required',
'class'=>'form-control',
'placeholder'=>'Message')) !!}
</div>
<div class="form-group">
{!! Form::submit('Submit',
array('class'=>'btn btn-primary')) !!}
</div>
{!! Form::close() !!}
<ul>
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
<?php namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\ContactFormRequest;
class PagesController extends Controller {
public function home()
{
// Mail::send('emails.contact', array('name' => 'Justin' ), function($message){
// $message->to('justin@sfp.net', 'Justin')->subject('Test');
// });
return view('pages.index');
}
public function store(ContactFormRequest $request)
{
\Mail::send('emails.contact',
array(
'name' => $request->get('name'),
'email' => $request->get('email'),
'phone' => $request->get('phone'),
'message' => $request->get('message')
), function($message)
{
$message->from('justin@sfp.net');
$message->to('justin@sfp.net', 'Admin')->subject('Chyall Pharma Contact');
});
return \Redirect::route('/')->with('message', 'Thanks for contacting us!');
}
}
答案 0 :(得分:88)
问题出在PagesController
内的Mail::send
。
'message' => $request->get('message');
您使用的是变量名'message'
,应该避免使用。
注意:$ message变量始终传递给电子邮件视图,并允许 内联嵌入附件。所以,最好避免通过 视图有效负载中的消息变量。
来源:http://laravel.com/docs/5.0/mail#basic-usage在第一个音符中。
您可能需要将变量名称更改为其他名称。
'bodyMessage' => $request->get('message');
并且不要忘记更改contact.blade.php
中的变量名称
<p>
Name: {{ $name }}
</p>
<p>
{{ $email }}
</p>
<p>
{{ $phone }}
</p>
<p>
{{ $bodyMessage }} // This line.
</p>
答案 1 :(得分:1)
{!! Form::submit('Submit', array('class'=>'btn btn-primary')) !!}
此行需要非数组的第二个参数,请尝试将其更改为:
{!! Form::submit('Submit', '', array('class'=>'btn btn-primary')) !!}
答案 2 :(得分:1)
答案 3 :(得分:0)
当我使用了错误的表单方法时,我也遇到了这个错误。要创建文本输入,请务必使用text
方法,而不是input
方法。
{!! Form::text('name', null, ['class' => 'form-control']) !!}
而不是:
{!! Form::input('name', null, ['class' => 'form-control']) !!}
这是纠正了错误。 这是Laravel 5.3与Laravel Collective(即作曲家需要&#34; laravelcollective / html&#34;:&#34; ^ 5.3.0&#34;)
答案 4 :(得分:-1)
你添加了
吗?到composer.json:
“require”:{ “illuminate / html”:“5.0.*@dev” },
到app.php供应商数组
'照亮\ HTML \ HtmlServiceProvider',
到app.php别名数组
'Html'=&gt; '照亮\ HTML \ HtmlFacade',
'Form'=&gt; '照亮\ HTML \ FormFacade',
然后
composer update