Laravel - 邮件动态主题(使用 SparkPost)

Laravel - Mailables Dynamic Subject (using SparkPost)

我有一个可邮寄的邮件,除了动态设置主题外,我真的没有任何问题。对于我的生活,我无法将主题行更改为编程文本以外的任何内容(例如 - 您的帐户已准备就绪)但我希望能够说 "Your Account is Ready {{$user->name}}".

但是,当我这样做时,返回了以下错误:

"message": "Client error: `POST https://api.sparkpost.com/api/v1/transmissions` resulted in a `422 Unprocessable Entity` response:\n{ \"errors\": [ { \"message\": \"substitution language syntax error in template content\", \"description\": \"Error while compili (truncated...)\n",
    "exception": "GuzzleHttp\Exception\ClientException",
    "file": "C:\xampp\htdocs\truckin\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php",
    "line": 113,
    "trace": [

我可以在电子邮件正文中传递像 {{$user->name}} 这样的变量,但我不能将任何变量传递给我的可邮寄主题。

目前,邮件有这个模板:

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

use App\Shipment;

class newFreightBill extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public $shipment;

    public function __construct(Shipment $shipment)
    {
        $this->shipment = $shipment;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->from('myEmail@email.com')
                    ->subject('New Account Created')
                    ->view('emails.account.created');
    }
}

我正在使用 Laravel 5.4。

public function build()
    {
        $data['name']     = 'pass your user name here';
        return $this->from('myEmail@email.com')
                    ->subject('New Account Created')
                    ->view('emails.account.created',$data);
    }
  1. 在你的视图页面(emails.account.created)你可以这样调用"Your Account is Ready {{$user->name}}"