200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > laravel5.6 使用mail发送附件邮件

laravel5.6 使用mail发送附件邮件

时间:2022-08-11 10:59:07

相关推荐

laravel5.6 使用mail发送附件邮件

模型:

<?phpnamespace App\Mail;use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Mail\Mailable;use Illuminate\Queue\SerializesModels;class SendMail extends Mailable implements ShouldQueue{use Queueable, SerializesModels;/*** Create a new message instance.** @return void*/private $data;public function __construct($data){$this->data = $data;}/*** Build the message.** @return $this*/public function build(){return $this->view('mon')->subject('测试邮件')->attach(storage_path($this->data['file_path']), ['as' => $this->data['file_name']]);}}

控制器:

public function sendMail(){$to = '15033245576@';$file_name = '语言学资料.pdf';$file_name = "=?UTF-8?B?".base64_encode($file_name)."?=";$info['file_path'] = 'test.pdf';$info['file_name'] = $file_name;$mail = (new SendMail($info))->onQueue('mail');Mail::to($to)->queue($mail);if(count(Mail::failures()) < 1){return '发送邮件成功,请查收!';}else{return '发送邮件失败,请重试!';}}

注意:改代码后需要执行一下命令,否则有可能发送邮件失败

!!!发邮件前需要缓存清理(进入虚拟机,执行一下操作):

重启队列

php artisan queue:restart

清楚缓存

php artisan config:cache

php artisan cache:clear

php artisan route:clear

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。