首页 > 解决方案 > 如何在控制器 laravel 邮件上添加更多参数

问题描述

我想使用 Laravel 发送电子邮件并使用此代码成功

Mail::to($email)->send(new SendMail($name))

现在我想用这段代码发送更多参数,比如主题,但是没有用。没有错误消息,但未发送电子邮件。

Mail::send(new SendMail($name function($message) use ($email){
    $message->to($email)->subject('Verify your Account');
}));

有什么建议么?提前致谢!

标签: laravelmailer

解决方案


你可以使用类似的东西

   $template = 'view.email';
   $paramets = ['data'=>$data];//Your to value to print in email
   $email = 'to@email.com'// to email 
   $cc = 'cc@email.com' // or null
   $toName = 'John Doe' // or null
   $subject = 'Verify your Account';

   Mail::send($template, $parameters, function($message) use($email,$cc,$toName,$subject) {
    $message->from(env('sender'), env('nameSender'));
    if($cc) $message->cc($cc);
    $message->to($email, $toName)
                ->subject($subject);
   });

我正在使用通用方法。所以我可以用这个方法来处理我需要发送的所有电子邮件


推荐阅读