Home Backend Development PHP Tutorial Markdown implementation of sending email code in Laravel5.5

Markdown implementation of sending email code in Laravel5.5

Feb 28, 2018 pm 02:06 PM
markdown mail

laravel supports markdown format for sending emails starting from version 5.4. I had time to try it on version 5.5 today. After using it, I found it very easy to use. I will make a simple record here.
Follow my steps below, you can also succeed, try it now!

Create Markdown template

php artisan make:mail Activate --markdown=emails.activate
Copy after login

After executing this command, the file Activate.php will be generated under the app/mail directory:

   namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Models\ActivateModel;
class Activate extends Mailable
{
    use Queueable, SerializesModels;
    private $activate;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(ActivateModel $activate)
    {
        $this->activate = $activate;
    }
    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
      return $this->markdown('emails.activate')->with('activate', $this->activate);
    }
}
Copy after login

and the template will be generated File, in resource/views/emails/activate.blade.php:

  @component('mail::message')
# 欢迎注册使用 Laravel
点击下面按钮进行激活。
@component('mail::button', ['url' => 'http://www.laravel.com'])
激活
@endcomponent
Thanks,<br>
{{ config(&#39;app.name&#39;) }}
@endcomponent
Copy after login


Email configuration

Sending emails requires basic configuration To support, configure it in the .env file. Here I use the 163 mailbox as an example:

   MAIL_DRIVER=smtp
MAIL_HOST=smtp.163.com
MAIL_PORT=25
MAIL_USERNAME=账号
MAIL_PASSWORD=密码
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=全局发件人地址
MAIL_FROM_NAME=全局发件人名称
Copy after login

Send call

Introduce Activate where you need to send emails, and use the Mail Facade The to method is called, I will make a simple route for testing here:

   # routes/web.php
Route::get(&#39;sendEmail&#39;, &#39;IndexController@sendEmail&#39;);
``` 
```php
# app/Http/Controllers/IndexController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use App\Mail\Activate;
class IndexController extends Controller
{
  public function sendEmail()
  {
    // ... code
    // 调用方式
    Mail::to(&#39;demo@example.com&#39;)->send(new Activate($activate));
  }
}
Copy after login


Execute the test

Execute the command in the project root directory:

php artisan serve
Copy after login

After starting the server, open the browser and enter the URL http://localhost:8000/sendEmail, and then check whether the sending mailbox has received the email.

Related recommendations:

implementation code of markdown document management tool in php

A brief introduction to markdown editor

markdown How to get the text content of markdown

The above is the detailed content of Markdown implementation of sending email code in Laravel5.5. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Outlook emails lost from control panel in Windows 11 Outlook emails lost from control panel in Windows 11 Feb 29, 2024 pm 03:16 PM

Is the Outlook mail icon missing from Windows 11's Control Panel? This unexpected situation has caused confusion and concern among some individuals who rely on OutlookMail for their communication needs. Why don't my Outlook emails show up in Control Panel? There may be several possible reasons why there are no Outlook mail icons in Control Panel: Outlook is not installed correctly. Installing Office applications from the Microsoft Store does not add the Mail applet to Control Panel. The location of the mlcfg32.cpl file in Control Panel is missing. The path to the mlcfg32.cpl file in the registry is incorrect. The operating system is not currently configured to run this application

Say goodbye to the Remote Mail Slot protocol in Windows 11 Say goodbye to the Remote Mail Slot protocol in Windows 11 Apr 14, 2023 pm 10:28 PM

We've been talking lately about the many features Microsoft plans to add to its latest operating system, Windows 11. But don't think that Microsoft will add nothing and take nothing back. In fact, the software giant started removing quite a few old features. After announcing plans to decommission MSDT functionality ahead of the release of Windows 12, a Redmond developer has more bad news. We are actually talking about remote mail slot legacy tool. Trust us when we say you actually want to know this. Microsoft has started deprecating this feature in build 25314. We are sure you remember that just a few days ago, Microsoft released build 25314 in its new canary channel. The above version contains many new features

PHP sends emails asynchronously: avoid long waits for emails to be sent. PHP sends emails asynchronously: avoid long waits for emails to be sent. Sep 19, 2023 am 09:10 AM

PHP sends emails asynchronously: avoid long waits for emails to be sent. Introduction: In web development, sending emails is one of the common functions. However, since sending emails requires communication with the server, it often causes users to wait for a long time while waiting for the email to be sent. In order to solve this problem, we can use PHP to send emails asynchronously to optimize the user experience. This article will introduce how to implement PHP to send emails asynchronously through specific code examples and avoid long waits. 1. Understanding sending emails asynchronously

Word mail merge prints blank page Word mail merge prints blank page Feb 19, 2024 pm 04:51 PM

If you find that blank pages appear when printing a mail merge document using Word, this article will help you. Mail merge is a convenient feature that allows you to easily create personalized documents and send them to multiple recipients. In Microsoft Word, the mail merge feature is highly regarded because it helps users save time manually copying the same content for each recipient. In order to print the mail merge document, you can go to the Mailings tab. But some Word users have reported that when trying to print a mail merge document, the printer prints a blank page or doesn't print at all. This may be due to incorrect formatting or printer settings. Try checking the document and printer settings and make sure to preview the document before printing to ensure the content is correct. if

How Vue3 parses markdown and implements code highlighting How Vue3 parses markdown and implements code highlighting May 20, 2023 pm 04:16 PM

Vue implements the blog front-end and needs to implement markdown parsing. If there is code, it needs to implement code highlighting. There are many markdown parsing libraries for Vue, such as markdown-it, vue-markdown-loader, marked, vue-markdown, etc. These libraries are all very similar. Marked is used here, and highlight.js is used as the code highlighting library. The specific implementation steps are as follows: 1. Install dependent libraries. Open the command window under the vue project and enter the following command npminstallmarked-save//marked to convert markdown into htmlnpmins

How to Fix Outlook Email Stuck in Outbox Issue How to Fix Outlook Email Stuck in Outbox Issue May 01, 2023 am 10:01 AM

Recently, many users have reported the issue of Outlook emails getting stuck in the outbox. Even after several attempts to send the email, the issue was not resolved. When you see this issue and check your outbox folder, the message will be stuck there. Possible reasons for emails getting stuck in Outlook outbox: The attachments in the email exceed the size limit, which slows down the sending process. Outlook account authentication issues with mail server Incorrect send/receive settings in Outlook or mail server offline Outlook. Outlook data files are being used by some other software. Antivirus software scans outgoing emails. If this problem has been bothering you and you are unable to send an email

A public preview is coming soon, including the latest Outlook app for Windows 11 and Windows 10. A public preview is coming soon, including the latest Outlook app for Windows 11 and Windows 10. May 09, 2023 am 08:07 AM

As part of updating native apps for Windows 11, Microsoft plans to release a new Outlook. The app was built from the ground up and is now being prepared for preview, which will likely be announced during Microsoft's Windows 11 hybrid event. The project is called "ProjectMonarch" and this new Outlook has been in development for over a year. This is a reboot of the web app that aims to unify all existing Windows email clients such as Mail and Calendar as well as the desktop version of Outlook. With OutlookOne, Microsoft hopes to help users manage their email across different desktop platforms. There are many ways to access

PHP email tracking function: understand user behavior and feedback on emails. PHP email tracking function: understand user behavior and feedback on emails. Sep 19, 2023 am 08:51 AM

PHP email tracking function: understand user behavior and feedback on emails In modern society, email has become an indispensable part of people's daily life and work. For businesses, sending emails is one of the important ways to communicate with customers and promote products or services. However, after an email is sent, how do we know whether it was received, read, or how the user reacted to the content of the email? At this time, the email tracking function becomes particularly important. The email tracking function can help us understand user behavior and feedback on emails

See all articles