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

时间:2019-02-24 12:44:56

标签: php laravel-5.7 laravel-mail

$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');
}
}

1 个答案:

答案 0 :(得分:0)

以此更改您的构建功能并进行检查。还要确保在数组中传递email参数。

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