Home > Enterprise >  Laravel 7 | Some recipients receive empty emails
Laravel 7 | Some recipients receive empty emails

Time:02-22

I have an laravel 7 application and use smtp with google services to send my emails.

However some clients receive the emails with attachments, but no body. The content of the email is completely blank. Most mail platforms (hotmail, outlook, gmail, mail on mac) receive the complete email. It's just some mail providers receive the email without a body.

I believe this might have to do with some security measures or not supporting HTML emails.

How can I ensure that also these clients receive my emails?

I use .blade.php files to send my emails.

example of one of my email files:

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class CandidateMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($message_details)
    {
        //

        $this->message_details = $message_details;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $email = $this->view('mail/candidate')
            ->subject($this->message_details['subject'])
            ->with(['message_details' => $this->message_details]);

        if ($this->message_details['attachments']) {
            $email->attachFromStorage($this->message_details['attachments']);
        }

        return $email;
    }
}

CodePudding user response:

you had to build your constructor the variable $message_details does not return anything,

public $message_details = "";

CodePudding user response:

Need to declare public property public $message_details here details

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class CandidateMail extends Mailable
{
    use Queueable, SerializesModels;

    public $message_details;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($message_details)
    {
        //

        $this->message_details = $message_details;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $email = $this->view('mail/candidate')
            ->subject($this->message_details['subject'])
            ->with(['message_details' => $this->message_details]);

        if ($this->message_details['attachments']) {
            $email->attachFromStorage($this->message_details['attachments']);
        }

        return $email;
    }
}
  • Related