如何在可邮寄文件或带有数据的控制器上设置电子邮件发件人?

How to set email sender on mailable file or Controller with data?

$created array 包含电子邮件值和姓名等等。 return $this->view('emails.created'); 工作正常,但我想让电子邮件发件人成为 $created->email。或者我的控制器 Mail::to('email')->from($created->email)->send(new Created($created)); 这样。但是两种方法都行不通。我该如何处理我的 app\Mail\Created.php 文件中的这个变量数组?我需要一些帮助。

class Created extends Mailable
{
use Queueable, SerializesModels;

/**
 * The created instance.
 *
 * @var created
 */
public $created;
/**
 * Create a new message instance.
 *
 * @return void
 */
public function __construct($created)
{
    $this->created = $created;
}

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->from($created->email)->view('emails.created');
}
}

用这个改变你的构建函数并检查。还要确保在数组中传递电子邮件参数。

public function build()
{
   return $this->from($this->created->email)->view('emails.created');
}