Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

TutsPlus.com:
How to Send Emails in Laravel
Jan 05, 2018 @ 18:25:33

The TutsPlus.com site has posted a tutorial for the Laravel users out there showing you how to send emails with built-in functionality via the framework's Mail API.

In this article, we're going to explore the Mail API in the Laravel web framework. Laravel takes advantage of the popular SwiftMailer library, which is easy to use and comes with a variety of email drivers to choose from. In the latter stages of the article, we'll go through an in-depth demonstration of the concepts discussed in the first half of the article.

The tutorial starts with the setup and configuration you'll need to get the mail system up and running. They don't help you set up the backend (like sendmail or Mailgun) but they do describe the options in the configuration required for methods like SMTP sending and local sending. Next they show an example of a "mailable" class that creates a "demo" email and defines various settings including the "from" address, the content (from a view), variables to pass to the view and an image attachment. The view for the example is also included, making use of the Blade templating to replace placeholders with variable values.

tagged: email laravel tutorial mailable class example

Link: https://code.tutsplus.com/tutorials/how-to-send-emails-in-laravel--cms-30046

Laravel News:
Learn How to Send an Email on Error Exceptions
Apr 18, 2017 @ 15:25:03

On the Laravel News site there's a quick tutorial posted showing you how to send an email when an exception is thrown in your Laravel-based application using the "mailable" functionality.

You’ve created a new Laravel app for your client and deployed it on the production server. Everything was working fine till a customer has a problem with the app because of some buggy code. He immediately leaves the app, and the same thing happens with multiple customers before you know about the bug. You fix the bug, and then everything is on track.

But what if you were notified immediately through e-mail (or another service) about the bug and you fix it ASAP. In Laravel, this can be done easily and in this post, we’re going to learn how.

The post talks about how errors and exceptions are handled in Laravel applications and how, with a bit of custom code, you can create you own handler and a "mailable" class it can use (an ExceptionOccured mailer) to send a full stack trace when an error is thrown. There's also a link to a package that can be installed that helps to make setup even easier.

tagged: send email laravel exception tutorial mailable handler

Link: https://laravel-news.com/email-on-error-exceptions

Laravel News:
In Laravel 5.4 You Can Use Markdown in Your Emails
Dec 14, 2016 @ 16:19:10

As is mentioned in this post on the Laravel News site one of the improvements coming in Laravel v5.4 will be the ability to use Markdown formatting in your emails.

Laravel 5.3 introduced two new features around email, the Mailables and Notifications which allow you to send the same message through email, SMS, and other channels.

Building on top of these improvements, Laravel 5.4 is going to include a brand new Markdown system for creating email templates.

Under the hood, this feature implements the Parsedown parser with its companion, Markdown Extra so you can use tables.

They go on to describe how this feature is integrated with the "components and slots" handling also recently introduced in the framework for things like headers, messages, layouts and tables. Also included is some example code showing how to return the Markdown parsed version of a view, using them in notifications and how to use inline styling.

tagged: laravel markdown email mailable formatting output tutorial v54 framework

Link: https://laravel-news.com/laravel-markdown-emails

Freek Van der Herten:
Sending a welcome mail with Laravel 5.3
Oct 04, 2016 @ 16:15:35

Freek Van der Herten has posted a new tutorial to his site showing you a method for sending a "welcome" email for your Laravel (5.3) application using the recently added "mailables" functionality.

Recently I was working an a project where, in order to use the webapp, users should first apply for an account. Potential users can fill in request form. After the request is approved by an admin they may use the app.

Our client expected that the barrier to request an account should be very low. That’s why the request form doesn’t contain a password field. Instead, when an account is approved, a welcome mail is sent with a link to where the user can specify a password.

In this post I’d like to show you how we solved this with Laravel 5.3’s mailables.

He starts with a high level overview of what he's trying to accomplish: sending the approval when the admin approves a new user in the system. He includes all the code you'll need to create:

  • the "approve" method in the User model
  • the event handler for the "UserApproved" event
  • generating the password reset hash/token
  • the actual code for the mailable class to send the message

He also includes the view for the email's contents, a simple "WelcomeController" to handle the user responding to the message and the view for the verification and password reset "welcome" page.

tagged: laravel tutorial send welcome email approval mailable event

Link: https://murze.be/2016/10/sending-welcome-mail-laravel-5-3/

Scotch.io:
Easy and Fast Emails with Laravel 5.3 Mailables
Aug 26, 2016 @ 16:32:01

The Scotch.io blog has posted another Laravel-related tutorial, this time focusing in on "mailables", a new feature in the latest release of Laravel (v5.3) that makes sending emails simpler.

Laravel 5.3 has just been released and there are a ton of great new features. One of the major improvements is in how you send mail in your applications.

They start with a look at how you might send emails in previous versions of the Laravel framework using the Mail::send method with a set of options and a callback. The tutorial then moves on to v5.3 and introduces the idea behind "mailables" and some simple examples. They show how to create a custom mailable-based class and the resulting code. They walk you through how to pass data into the email views, changing up the mailer configuration, sending extra parameters and sending the emails. They also include information about email queueing using Laravel's built-in queuing functionality.

tagged: easy email laravel v53 mailable tutorial introduction

Link: https://scotch.io/tutorials/easy-and-fast-emails-with-laravel-5-3-mailables`

Matt Stauffer:
Introducing Mailables in Laravel 5.3
Aug 05, 2016 @ 15:57:32

Matt Stauffer has posted the next in his "what's coming in Laravel 5.3" series today with this look at "mailables" to help make sending mail simpler in Laravel-based applications.

For the longest time, sending mail in Laravel has felt clumsy compared to the relatively light APIs of most other Laravel features. I'm not saying it's awful—it's still so much cleaner than its competitors--but it's often confusing to figure out what goes in the closure and what doesn't, what the parameter order is, etc.

Mailables are PHP classes in Laravel 5.3 that represent a single email: "NewUserWelcome", or "PaymentReceipt". Now, similar to event and job dispatching, there's a simple "send" syntax, to which you'll pass an instance of the class that represents what you're "dispatching"; in this context, it's an email.

He gives an example of the updated syntax for calling these "mailables", how to create them with the artisan command and their structure/usage. He also shows how to pass data into the object and some other included features (like customizing the delivery list, queuing and working with attachments).

tagged: mail sending laravel mailable class interface overview

Link: https://mattstauffer.co/blog/introducing-mailables-in-laravel-5-3


Trending Topics: