Laravel版本:5.3 PHP版本:7.0 数据库驱动程序&版本:MySQL 5.7 说明:
我在尝试设置发件人(而不是)时遇到了这个问题,我最终收到了一个看起来像这样的错误
Symfony \ Component \ Debug \ Exception \ FatalThrowableError:[]运算符没有 支持字符串 C:\瓦帕\ WWW \企业\厂商\ laravel \框架\ SRC \照亮\邮件\ Mailable.php:384
即使我输入的是电子邮件字符串它与我在mail.php中设置的系统电子邮件地址冲突。
系统中没有其他地方在尝试将电子邮件设置为从其他电子邮件地址发送时出错。我正在尝试从授权用户电子邮件发送它
所以,在我的mailable课程中,我正在使用
public function build()
{
return $this->from(Auth::user()->email)
} ->view('mailbox.sendmail');
但在我的mail.php中
'from' => [
'address' => 'no-reply@swellsystem.com',
'name' => 'Swell Systems',
],
解决方案是什么?
这是我的Mailable - UserEmail类。我用它来发送排队的用户电子邮件。我从$ request
获得了一些依赖项<?php
namespace App\Mail;
use Auth;
use DB;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class UserEmail extends Mailable
{
use Queueable, SerializesModels;
public $from, $subject, $content;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($from, $subject, $content)
{
//
$this->from = $from;
$this->subject = $subject;
$this->content = $content;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from($this->from)
->view('mailbox.sendmail')
->subject('Subject:' . $this->subject)
->with(['body' => $this->content])
}
我从控制器中调用它
namespace App\Http\Controllers;
use App\Mail\UserEmail;
use Auth;
use Mail;
$from = Auth::user()->email;
$subject = $request->input( 'subject' );
$content = $request->input( 'content' );
Mail::to($request->to)->later($when, (new UserEmail($from, $subject, $content))->onQueue('emails'));
这是一个例外,因为它会引发更多细节
Symfony \ Component \ Debug \ Exception \ FatalThrowableError:[]运算符没有 支持字符串 C:\瓦帕\ WWW \企业\厂商\ laravel \框架\ SRC \照亮\邮件\ Mailable.php:384
堆栈跟踪
1。 C:\瓦帕\ WWW \企业\厂商\ laravel \框架\ SRC \照亮\邮件\ Mailable.php(312): Illuminate \ Mail \ Mailable-&gt; setAddress('nmorgan @ designl ...',NULL, 'from')2。 C:\ WAMP \ WWW \企业\程序\邮件\ UserEmail.php(51): 照亮\邮件\ Mailable-肽从( 'nmorgan @ designl ...') - [内部功能]:App \ Mail \ UserEmail-&gt; build()3。 C:\瓦帕\ WWW \企业\厂商\ laravel \框架\ SRC \照亮\集装箱\ Container.php(508): call_user
如果我在课堂上发表评论,则会从系统发送电子邮件(mail.php)。否则,它会抛出错误
它与我的设置中的任何内容有关吗?有什么我想念的。
Mail.php
'from' => [
'address' => 'no-reply@example.com',
'name' => 'System',
],
我在Laravel.io论坛上发现了这个帖子,但我没有留言变量。
<https://laravel.io/forum/10-05-2016-mailablephp-line-382-operator-not-supported-for-strings>
我很肯定$ this-&gt;来自或者Auth :: user() - &gt;电子邮件肯定是一个字符串..我把它丢弃了,它是“emal@user.com”但我把它全部一起删除了并输入'name@example.com'并得到相同的错误
答案 0 :(得分:0)
通过从app.php中删除并在每封邮件中设置来修复它