Ad

Laravel 5.2 E-mail Not Delivered No Exception

- 1 answer

I'm trying to reset a password in laravel 5.2 (upgraded from 5.2) and sending a password token to my mail (using laravels 5.2 new make:auth).

  1. Set mail driver to log
  2. Go to: http://localhost/public/password/reset
  3. Fill in e-mail address and click "send password reset link"
  4. The e-mail is stored in the log file
  5. Change mail driver to smtp
  6. Run php artisan config:cache
  7. Do action 2 and 3 again
  8. No error / exception is shown
  9. Message of laravel is "We have e-mailed your password reset link!"

My .env file

APP_ENV=local
APP_DEBUG=true
APP_KEY=xxxxxxxxxxxxxxxxxxxxxxxxx

DB_HOST=localhost
DB_DATABASE=xxxxxxxxxx
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=xxxx.xxxxxx.xx
MAIL_PORT=25
[email protected]
MAIL_PASSWORD=xxxxxxxxxxxxx
MAIL_ENCRYPTION=tls

I configured in mail.php this line

 'from' => ['address' => '[email protected]', 'name' => 'xxx'],

At first it gave exceptions since i did not use the right credentials / settings. That error is gone.

a) How can i check if the mail is sent? b) How can i check why it's not delivered? c) What am i doing wrong?

Ad

Answer

I am not sure what the exact problem is, but i will give you my working code (also using 5.2), and then you can check if there is something different between our codes:

.env

MAIL_DRIVER=smtp
MAIL_HOST=asmtp.unoeuro.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=********
MAIL_ENCRYPTION=tls

Be sure that your mail server is using TLS, or disable this. They'll usually tell if they accept tls encryption.

mail.php

'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'asmtp.unoeuro.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => "[email protected]", 'name' => "Hello World"],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),

Setup a view with a controller and hardcode this in the controller, so that when you visit the view, the following code will run: (Remember to assign $thename and $theemail or hardcode them

use Mail;

$mailvar = ['name' => $thename, 'email' => $theemail];

Mail::send('Mailtemplate.view', ['mailvar' => $mailvar], function ($message) use ($mailvar) {

        $message->from('[email protected]', 'google.com');
        $message->to($mailvar['email'], $mailvar['name'])->subject('You recieved a message');

    });

Remember to create the view Mailtemplate.view where the mail should be shown. You can use $name and $email in the view as variables.

Your mailtemplate sho in the view as variables.

Your mailtemplate should look something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>

<head>
    <style type="text/css" media="screen">';

    </style>
</head>

<body>
Name: {{ $mailvar['name'] }}
Email: {{ $mailvar['email'] }}
</body>
</html>
Ad
source: stackoverflow.com
Ad