Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mecjos's avatar

File Attached Mail Can not be sent via Aws SES

Hi I want to send email with raw data atached image via amazon SES. Without attachment mailler is working but when image file attached it doesn't send the mail. I don't get any error message both from amazon ses and queue worker.. What's the proper way to send file attached mails. My codes are as follows;

MailController:

public function SendFeedback(Request $request)
    {
        try {
            $data = [
                'userName' => $request->user()->fullname,
                'userId' => $request->user()->id,
                'message' => $request->message,
                'subject' => $request->subject,
                'route' => $request->route
            ];
            $fileData = null;
            if ($request->hasFile('image')) {
                $fileData = [
                    'fileContent' => base64_encode($request->file('image')->getContent()),
                    'fileAs' => $request->file('image')->getClientOriginalName()
                ];
            }
            Mail::to('[email protected]')->send(new SendFeedback($data, $fileData));
        } catch (Exception $e) {
            return response()->json($e->getMessage(), 500);
        }
    }

App/Mail/SendFeedback:

public function __construct($data = [], $fileData = [])
    {
        $this->userName = $data['userName'];
        $this->userId = $data['userId'];
        $this->feedbackType = $data['subject'];
        $this->message = $data['message'];
        $this->route = $data['route'];
        $this->fileData = $fileData;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $mail = $this->from('[email protected]', $this->userName)
                    ->subject($this->feedbackType . ' you have a notification!')
                    ->markdown('emails.feedback');
        if (isset($this->fileData)) {
            $mail = $mail->attachData(base64_decode($this->fileData['fileContent']), $this->fileData['fileAs']);
        }

        return $mail;
    }
}
0 likes
4 replies

Please or to participate in this conversation.