1

I can make email verification using default template from Laravel 5.8.

Now, I want to customize the email.

Can you help me?

I tried to follow instructions from this: https://medium.com/@lordgape/custom-verification-email-notification-laravel-5-8-573ba3183ead. There is no error, but no email sent.

When I switch back to default verification, the default email is sent.

Edit:

The steps I tried so far:

  • Create a mailable for email verification.
  • Create views for new email template
  • override toMailUsing() using the following code in AppServiceProvider.php:
VerifyEmail::toMailUsing(function ($notifiable){
                $verifyUrl = URL::temporarySignedRoute(
                    'verification.verify',
                    Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
                    ['id' => $notifiable->getKey()]
                );

                // dd($notifiable);
                return new EmailVerification($verifyUrl, $notifiable);
            });
  • edit mailable, add two variable: $verifyUrl and $user.
  • edit __construct function:
public function __construct($url, User $user)
    {
        $this->user = $user;
        $this->verifyUrl = $url;
    }
  • edit build() function in mailable, add return $this->view('emails.verifyUser'); (views of custom template).
  • No error, "please verify your email" page is shown like usual. But no email sent.
  • From what I see that guide is lacking in crucial elements like the verification route which the user will hit once they follow the URL. Can you share how you tried? – apokryfos Jun 26 '19 at 06:47
  • you can use **regex** – Nipun Tharuksha Jun 26 '19 at 06:47
  • We need more information, because Laravel 5.8 have email verification. and if you want to change design for email or page you can do it ! – vipmaa Jun 26 '19 at 06:48
  • @apokryfos, Ok, I edited the post. – Zacharias Hendrik Jun 26 '19 at 07:37
  • @vipmaa, actually I only want to change design for email. I can not edit the default template because it is in vendor folder. – Zacharias Hendrik Jun 26 '19 at 07:41
  • https://stackoverflow.com/questions/52231870/laravel-email-verification-template-location might be an alternative way to do this. You'll still need to do the first and second step but for the 3rd one instead of using the service provider you can override the user method itself – apokryfos Jun 26 '19 at 07:57
  • @ZachariasHendrik YOU CAN PUBLISH IT TO YOUR VIEW FOLDER BY USING `php artisan vendor:publish` – vipmaa Feb 04 '20 at 22:23

1 Answers1

0

If you want to only customize the look and the layout of the sent email and not the contents (text) of the mail you have to publish the view files of the notification and mail components.

To do so you can type:

php artisan vendor:publish --tag=laravel-notifications
php artisan vendor:publish --tag=laravel-mail

These command will copy the Laravel mail message templates from the vendor folder to resources/views/vendor/notifications and resources/views/vendor/mail.

In the former path you have the email.blade.php which is basically the the MailMessage layout. (In fact you can see all the available slots you can customize with MailMessage).

In the latter path you can find the markdown and html components (that are also used in the MailMessage layout I mentioned earlier). You can take a look at the various files and modify them.

Note: the changes you makes to these templates would apply to any email message that you send, also if you create a new notification and mailable, it would still use these modified templates.

You can use this method to do global changes to the look of an email and, for example customize the header to include the logo of your company, etc.

If you just have to edit the content (texts) of an email message, you should still have to create your custom notification/mailable.

Quick tip: you can preview emails in the browser to make adjustments to the layout and texts quickly, as you don't have to fire off the notification all the time: https://medium.com/@jaouad_45834/preview-your-emails-notifications-in-browser-laravel-9058d8c856c4

mdexp
  • 3,492
  • 2
  • 9
  • 20