Home Articles

Mailable bug .. laravel 5.3和5.4无法从用户发送

Asked
Viewed 1922 times
0

Laravel版本:5.3 PHP版本:7.0数据库驱动程序和版本:MySQL 5.7描述:

我在尝试设置发件人(而不是)时遇到了这个问题,最终我得到了一个看起来像这样的错误

Symfony \ Component \ Debug \ Exception \ FatalThrowableError:[]运算符不支持C:\ wamp \ www \ enterprise \ vendor \ laravel \ framework \ src \ Illuminate \ Mail \ 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:\ wamp \ www \ enterprise \ vendor \ laravel \ framework \ src \ Illuminate \ Mail \ Mailable.php中的字符串:384

Stack trace

1 . C:\ wamp \ www \ enterprise \ vendor \ laravel \ framework \ src \ Illuminate \ Mail \ Mailable.php(312):Illuminate \ Mail \ Mailable-> setAddress('nmorgan @ designl ...',NULL,'来自')2 . C:\ wamp \ www \ enterprise \ app \ Mail \ UserEmail.php(51):Illuminate \ Mail \ Mailable-> from('nmorgan @ designl ...') - [内部函数]:App \ Mail \ UserEmail - > build()3 . C:\ wamp \ www \ enterprise \ vendor \ laravel \ framework \ src \ Illuminate \ Container \ Container.php(508):call_user

如果我在课堂上注释掉电子邮件是从系统发送的(mail.php) . 否则,它会抛出错误

它与我的设置中的任何内容有关吗?有什么我想念的东西 .

Mail.php

'from' => [
'address' => 'no-reply@example.com',
'name' => 'System',
],

我在Laravel.io论坛上发现了9个月前发布的内容,但我没有消息变量 .

<https://laravel.io/forum/10-05-2016-mailablephp-line-382-operator-not-supported-for-strings>

我很肯定$ this-> from或者Auth :: user() - > email绝对是一个字符串..我把它丢弃了,它是“emal@user.com”但是我把它全部删除了并放了'name @ example.com'并得到了同样的错误

1 Answer

  • 0

    通过从app.php中删除并在每封邮件中设置来修复它

Related