Monday, March 13, 2017

laravel 5.3 sendgrid categories

In laravel 5.2 this worked just fine, but since migrating to 5.3 i'm having issues getting the category sent in my email.

public function build()
    {
        return $this->view('mail.enquiry')
            ->getSwiftMessage()->getHeaders()->addTextHeader('X-SMTPAPI', json_encode(array("category" => array(env('BUSINESS_NAME')))))
            ->subject('Website Enquiry')
            ->to(env('MAIL_DEFAULT_TO_EMAIL'), env('MAIL_DEFAULT_TO_NAME'))
            ->from(env('MAIL_DEFAULT_FROM_EMAIL'), env('MAIL_DEFAULT_FROM_NAME'))
            ->replyTo(\Request::get('email'), \Request::get('full_name'));
    }

i get this error

BadMethodCallException in Mailable.php line 525:
Method [getSwiftMessage] does not exist on mailable.

every thing in this code works fine, but breaks as soon as I add this line:

    ->getSwiftMessage()->getHeaders()->addTextHeader('X-SMTPAPI', json_encode(array("category" => array(env('BUSINESS_NAME')))))



via cardi777

Advertisement