在laravel邮件中发送附件 [英] Sending attachment in laravel mail

查看:652
本文介绍了在laravel邮件中发送附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个人.我正在尝试发送带有附件的电子邮件.我所做的是:

everyone. I am trying to send email with attachment on it. What I have done is :

   controller code snippet:

     try{
           Mail::send(['name' => 'By System'],array(), function($msg) use ($email,$name,$message,$attachment,$ext,$display) {
                        $msg->from('ricket999@gmail.com', 'Markle Admin');
                        $msg->to($email)->subject('Payment Done')
                            ->setBody('This is to notify you that the employee named '.$name.' has been paid for the monthly payment. Thank You.','text/html')
                            ->attach(public_path().'/'.$attachment, ['as' => $display.'.'.$ext, 'mime' => 'application/pdf']);  });
        }
    catch(Exception $e){
             // if any error mark the mail sent status 0
             $result = DB::table('message')->where('name',$name)->where('email',$email)->update(['sent'=>'0']); 
            }

但它显示此错误:

    Type error: Argument 1 passed to Swift_Mime_SimpleMessage::attach() must implement interface Swift_Mime_MimeEntity, string given, called in E:\xampp\htdocs\email-send\app\Http\Controllers\HomeController.php on line 133

我错过了什么.我看到了

What have I missed. I saw this and this but it is same as mine and they say its working but why am I getting this error. Any kind of help are appreciated. Thank you.

推荐答案

您有2个问题:

  1. 在将mime设置为application/pdf

您的存档路径错误. 代替 E:\\xampp\\htdocs\\email-send\\public\\files\\1520764563.zipE:\\xampp\\htdocs\\email-send\\public/files/1520764563.zip

The path to your archive is wrong. Instead of E:\\xampp\\htdocs\\email-send\\public\\files\\1520764563.zip it is E:\\xampp\\htdocs\\email-send\\public/files/1520764563.zip

关于Argument 1 passed to Swift_Mime_SimpleMessage::attach() must implement interface Swift_Mime_MimeEntity, string given错误,我想这可以解决您的问题:

Regarding the Argument 1 passed to Swift_Mime_SimpleMessage::attach() must implement interface Swift_Mime_MimeEntity, string given error I suppose that this solves your problem:

    $swiftAttachment = Swift_Attachment::fromPath($correctPath); 
    $this->email->attach($swiftAttachment); // now attach the correct type

这篇关于在laravel邮件中发送附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆