htmlspecialchars()期望参数1为字符串(Laravel 5.7.1)

时间:2019-01-26 10:09:58

标签: php laravel email laravel-5.7

我正在尝试通过模板从联系页面发送邮件。邮件发送成功,但是当我尝试向用户显示给定的消息时,它显示了以下问题:

htmlspecialchars() expects parameter 1 to be string, object given (View: C:\laragon\www\square_chili\resources\views\partials\email\contactEmail.blade.php)

现在,我该如何解决这个问题呢??

contactEmail.blade.php:

<div class="card-body">
    <div class="subject">
        <h4>Subject</h4>
        <div class="subject-div">
            <h3>{{ $subject }}</h3>
        </div>
    </div>
    <div class="name">
        <h4>Name</h4>
        <div class="name-div">
            <h3>{{ $name }}</h3>
        </div>
    </div>
    <div class="email">
        <h4>Email Address</h4>
        <div class="email-div">
            <h3>{{ $email }}</h3>
        </div>
    </div>
    <div class="message">
        <h4>Message</h4>
        <div class="message-div">
            <h6>{{ $message }}</h6>
        </div>
    </div>
</div>

ContactController(存储区):

$mailData = [
    'name' => $request - > first_name.
    " ".$request - > last_name,
    'email' => $request - > email,
    'subject' => $request - > subject,
    'message' => $request - > message
];

Mail::send('partials.email.contactEmail', $mailData, function($message) use($mailData) {
    $message - > to($mailData['email']);
    $message - > subject($mailData['subject']);
    $message - > from('mymail@gmail.com');
});

2 个答案:

答案 0 :(得分:2)

在Contact控制器上,从对象运算符import {renderToStaticMarkup} from 'react-dom/server'; class App extends Component { render() { return ( <div className="App"> { rendertostaticmarkup(str) } </div> ); } } 中删除空格。

尝试

import {renderToStaticMarkup} from 'react-dom/server';

class App extends Component {
  render() {
    return (
      <div className="App" dangerouslySetInnerHTML={{__html:renderToStaticMarkup(str)}}/>
    );
  }
}

答案 1 :(得分:1)

只需更改变量名'message'

'msg' => $request->message