You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel发送邮件报语法错误:意外token=,期望]的问题排查

Laravel发送邮件触发500错误:语法错误排查与修复

问题场景

通过Postman调用接口发送邮件时,收到500服务器错误,返回错误信息:

"error": "syntax error, unexpected token "=", expecting "]""

控制器中调用邮件的代码如下:

Mail::to($user->email_address)->send(new ClientFinalRegistration($user));

错误根源

排查后定位到Mail/ClientFinalRegistration.php的build方法中,with方法的数组参数存在语法错误:数组内的'faqURL'项错误使用了单个=,而非PHP数组键值对要求的=>。错误代码片段:

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->subject($this->subject)
        ->markdown($this->view)
        ->with([
            'user' => $this->user,
            'faqURL' = $this->faqURL, // 此处语法错误
            'url' => $this->url,
        ]);
}

修复方案

将数组中错误的=替换为=>即可解决问题,修正后的代码:

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->subject($this->subject)
        ->markdown($this->view)
        ->with([
            'user' => $this->user,
            'faqURL' => $this->faqURL, // 修正为正确的键值对语法
            'url' => $this->url,
        ]);
}

内容的提问来源于stack exchange,提问作者dizon.ben

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 12:55:19