Luke Galea
Luke Galea

Reputation: 308

Laravel Sendgrid SMTP

Hi I am using Laravel as a backend to send out emails. I managed to do so by following this guide: https://sendgrid.com/docs/for-developers/sending-email/laravel/

This worked well when hosting the project on my local PC however I keep getting a 500 Server Error when the project is hosted on GoDaddy. From Sendgrid I also carried out Sender Authentication but I still get a 500 Server Error.

API Route:

Route::get('/mail', 'Auth\v1\AuthController@sendMail');

Controller Function Code:

public function sendMail(){
        $data = ['message' => 'This is a test!'];
        Mail::to('[email protected]')->send(new TestEmail($data));
        return '200 OK';
    }

Test E-Mail Class:

<?php

namespace App\Mail;

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

class TestEmail extends Mailable
{
    use Queueable, SerializesModels;

    public $data;

    public function __construct($data)
    {
        $this->data = $data;
    }

    public function build()
    {
        $address = '[email protected]';
        $subject = 'This is a demo!';
        $name = 'Jane Doe';

        return $this->view('emails.test')
                    ->from($address, $name)
                    ->cc($address, $name)
                    ->bcc($address, $name)
                    ->replyTo($address, $name)
                    ->subject($subject)
                    ->with([ 'message' => $this->data['message'] ]);
    }
}

I am getting the following error: [2019-08-02 11:37:36] production.ERROR: Connection could not be established with host smtp.sendgrid.net [Connection refused #111] {"exception":"[object] (Swift_TransportException(code: 0): Connection could not be established with host smtp.sendgrid.net [Connection refused #111] at /home/gthy6yfbfb5j/public_html/iotmarineapi/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:269) [stacktrace]

Upvotes: 0

Views: 1861

Answers (1)

Luke Galea
Luke Galea

Reputation: 308

The workaround for this was to use the Sendgrid API since SMTP needs to be setup properly in GoDaddy.

Upvotes: 1

Related Questions