【问题标题】:Laravel Mail::send() illegal offet 'name'Laravel Mail::send() 非法offet 'name'
【发布时间】:2015-04-11 06:35:42
【问题描述】:

我确信有一个简单的解决方案,但是在处理用于 Laravel Mail::send() 的表单输入时,我遇到了“非法字符串偏移”错误。

这是处理表单输入的代码,因为它必须是一个数组。

$msg = array(
    'name'=>Input::get('name'),
    'email'=>Input::get('email'),
    'message'=>Input::get('message')
);

然后我尝试通过 Mail::send() 发送它。

Mail::send('emails.question', $msg, function($message) {
    $message->to('myPersonalEmail@domain.com')->subject('Email from your website!');
});

app/views/emails/question.blade.php 模板非常简单。

{{ $msg['name'] }} <br/>
{{ $msg['email'] }} <br/>
{{ $msg['message'] }}

但我仍然收到以下错误。

    ErrorException (E_UNKNOWN)
Illegal string offset 'name' (View:
[intentionally omitted for privacy]/app/views/emails/question.blade.php)

我相信错误是指 $msg['name'] 不存在,但如果我返回视图,我根本不会收到错误。

return View::make('emails.questions')->with('msg',$msg);

我错过了什么?

【问题讨论】:

    标签: php email laravel sendmail mail-sender


    【解决方案1】:

    您已将$msg 作为关联数组传递,因此$msg 数组的项可用于$key 的视图。在您的情况下,这意味着$name$email 等等。 app/views/emails/question.blade.php 现在会是这样的

    {{ $name }} <br/>
    {{ $email }} <br/>
    {{ $message }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-28
      • 2015-05-07
      • 1970-01-01
      • 2015-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多