Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachments are not being sent #9

Open
CleytonBonamigo opened this issue Oct 12, 2018 · 1 comment
Open

Attachments are not being sent #9

CleytonBonamigo opened this issue Oct 12, 2018 · 1 comment

Comments

@CleytonBonamigo
Copy link

CleytonBonamigo commented Oct 12, 2018

Hello.

I'm trying to send attachments with e-mail, but are not being sended.
The email never comes, it's just to test.
If attachments are not send, the email arrives

Here is my code in App\Mail\OrderShipped.

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use function GuzzleHttp\Psr7\mimetype_from_filename;

class OrderShipped extends Mailable
{
    use Queueable, SerializesModels;

    protected $config;

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

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $attachments = json_decode($this->config['attachments']);
        return $this->view('welcome')
            ->attach($attachments[0]->path, [
                'as' => $attachments[0]->name,
                'mime' => mimetype_from_filename($attachments[0]->path)
            ]);
    }
}

Thanks.

@HidanJashin
Copy link

If your server is on Linux it might be an issue with ElasticTransport.php

Change
$attachedFilePath = storage_path('app\\' . $tempName);
for this
$attachedFilePath = storage_path('app/' . $tempName);

If you are on Laravel 5.5+
In the deleteTempAttachmentFiles method

Change
if (File::exists($file)) { File::delete($file); }
for this
if (file_exists($file)) { unlink($file); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants