1

Using laravel 5.7 with SwiftMailer library (SMTP to office365)


I have done my fair share of research and have not come across a problem like this. There are errors that I've seen and that were somewhat like this one, but they all made sens to me unlike this one.

I have no clue how to fix this and would love a second hand on this.


Error return:

fwrite(): SSL: The operation completed successfully.


config/mail.php has all the configuration as it should be:

'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.office365.com'),
'port' => env('MAIL_PORT', 587),                               //office 365 need to use 587
'encryption' => env('MAIL_ENCRYPTION', 'tls'),                 //office 365 need to use TLS
'username' => env('xxxx@xxxxxxx.xx'),
'password' => env('xxxxxxxxx'),

.env also has its configuration sorted out correctly:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587                                                  //office 365 need to use 587
MAIL_USERNAME=xxxx@xxxxxxx.xx
MAIL_PASSWORD=xxxxxxxxx
MAIL_ENCRYPTION=tls                                            //office 365 need to use TLS

postContact function in Controller

public function postContact(Request $request) {

//validation
    $this->validate($request, [
        'companyName' => 'required',
        'name' => 'required',
        'email' => 'required|email',
        'phone' => 'numeric',
        'message' => 'min:10']);

//request data from submitted form
    $data = array(
        'companyName' => $request->companyName,
        'name' => $request->name,
        'email' => $request->email,
        'phone' => $request->phone,
        'bodyMessage' => $request->message
    );

//send mail
    Mail::send('emails.contact', $data, function($message) use ($data){
        //$message->from($data['email']);
        $message->to('xxxx@xxxxxxx.xx');
        $message->subject('New email from xxxxxxxx');
    });

    return redirect('/');    }

Tomm
  • 1,021
  • 2
  • 14
  • 34
  • What is your php version? – Vaggelis Ksps Feb 18 '19 at 13:16
  • @VaggelisKsps 7.2.5 – Tomm Feb 18 '19 at 13:18
  • Do you have the same problem for example with mailtrap? If not it is probably some kind of restrictions or configuration of the office365. It may need an ssl on your website to determine that the connection is secure. It doesn't look like a laravel error but check this too https://stackoverflow.com/questions/49645176/laravel-sending-email-with-office-365-email?noredirect=1&lq=1 – Vaggelis Ksps Feb 18 '19 at 13:22
  • This does not happen with mailtrap, I was converting from development to live (so had to change mail server). Needing a ssl on your website seems unlikely to me if the mailserver credentials are correct. Where does one check the configurations of office365's smtp? – Tomm Feb 18 '19 at 13:26
  • Does the email is sent at all? According to microsoft docs Error success means that you don't have any error https://learn.microsoft.com/en-us/windows/desktop/Debug/system-error-codes--0-499- – Vaggelis Ksps Feb 18 '19 at 13:37
  • No the emails don't send, thats the whole reason im making this post..... – Tomm Feb 18 '19 at 13:39
  • Hi @Tomm, did you find a solution? – Stanley Umeanozie Mar 27 '19 at 20:47
  • @StanleyUmeanozie I have had a friend of mine run my code for me which all worked, so there was nothing wrong with the code. Then after some googling I came to the conclusion of reinstalling xampp (since the mail servers seemed to interupt weaith eachother). – Tomm Mar 28 '19 at 07:10

0 Answers0