Laravel 5.4 发送带有附件错误的邮件 - 使用 Mailtrap.io

Sai*_*nce 5 php email laravel laravel-mail laravel-5.4

我正在尝试在开发环境中发送带有附件的电子邮件 -mailtrap用于相同的用途。此附件可以是任何文件类型。但是,我总是最终收到错误:

Expected response code 250 but got code "502", 
with message "502 5.5.2 Error: command not recognized
Run Code Online (Sandbox Code Playgroud)

我不知道我在什么地方犯了什么错误,但我没有达到预期的结果,那就是发送带有附件的邮件。

附件文件位于public/email-attachments/文件夹内

这是我迄今为止尝试过的源代码:

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    $mailContent = cache('allEmailContents')->first();

    return $this->from('welcome@dprefumry.com')
                ->subject($mailContent->subject)
                ->view('emails.send')
                ->attach($mailContent->attachment, [
                    'as' => str_slug($mailContent->subject),
                    'mime' => File::mimeType($mailContent->attachment)
                ])
                ->with(['mailContent' => $mailContent]);
}
Run Code Online (Sandbox Code Playgroud)

routes/web.php文件中:

Route::get('/', function() {
    Mail::to('maddy@example.com')
            ->send(new SendWelcomeEmail());

    return view('welcome');
});
Run Code Online (Sandbox Code Playgroud)

我也尝试过发送邮件的旧方式,但没有成功:

Route::get('/', function() {
    $mailContent = cache('allEmailContents')->first();
    $data = $mailContent->toArray();

    Mail::send('emails.send', $data, function($mail) use ($mailContent, $data) {    
        $mail->to('maddy@example.com')->subject($mailContent->subject);
        $mail->from('welcome@example.com');
        $mail->attach($mailContent->attachment, [
            'as' => str_slug($mailContent->subject),
            'mime' => File::mimeType($mailContent->attachment)
        ])
    });

    return view('welcome');
});
Run Code Online (Sandbox Code Playgroud)

更新1:

这是.env文件:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=49xxxxxxx70
MAIL_PASSWORD=1fxxxxxxxxxx1e
MAIL_ENCRYPTION=null
Run Code Online (Sandbox Code Playgroud)

更新 2:

我只是在玩弄上传文件并存储它..然后将该文件作为附件调用并得出以下结论:

第一。如果我上传小于 5 MB 的文件,该文件将作为附件发送,没有任何问题。

第二。如果我上传的文件大于 5 MB,则会出现以下错误:

Expected response code 250 but got code "552",
with message "552 5.7.0 Message exceeded max message size of 5242880 bytes"
Run Code Online (Sandbox Code Playgroud)

以防万一,如果需要参考 php.ini

我有以下配置 php.ini

post_max_size = 20000M
upload_max_filesize = 10000M
max_file_uploads = 20
max_execution_time = 600000
Run Code Online (Sandbox Code Playgroud)

请帮我解决这个问题。任何帮助都受到高度赞赏。