laravel.com
Open in
urlscan Pro
2606:4700::6812:351
Public Scan
URL:
https://laravel.com/docs/5.0/mail
Submission: On August 02 via api from IT — Scanned from IT
Submission: On August 02 via api from IT — Scanned from IT
Form analysis
0 forms found in the DOMText Content
Skip to content Get started with PHP and Laravel faster than ever using Laravel Herd. Join us in Dallas, TX! Tickets are now available for Laracon US. Let's go to India! Tickets are now available for Laracon IN. Let's go to Europe! Tickets are now available for Laracon EU. Let's go down under! Tickets are now available for Laracon AU. Servers with PHP 8.3 are now available for provisioning via Laravel Forge. Deploy Laravel with the infinite scale of serverless using Laravel Vapor. How's your health? Check your application's vital signs using Laravel Pulse. Incoming transmission received. Laravel Reverb is now available! Take your administration backend to another dimension with Laravel Nova. Laravel is hiring! Help us build the future of Laravel. * PROLOGUE * Release Notes * Upgrade Guide * Contribution Guide * SETUP * Installation * Configuration * Homestead * THE BASICS * Routing * Middleware * Controllers * Requests * Responses * Views * ARCHITECTURE FOUNDATIONS * Service Providers * Service Container * Contracts * Facades * Request Lifecycle * Application Structure * SERVICES * Authentication * Billing * Cache * Collections * Command Bus * Core Extension * Elixir * Encryption * Envoy * Errors & Logging * Events * Filesystem / Cloud Storage * Hashing * Helpers * Localization * Mail * Package Development * Pagination * Queues * Session * Templates * Unit Testing * Validation * DATABASE * Basic Usage * Query Builder * Eloquent ORM * Schema Builder * Migrations & Seeding * Redis * ARTISAN CLI * Overview * Development Laravel Forge: create and manage PHP 8 servers. Deploy your Laravel applications in seconds. Sign up now!. Laravel Vapor: experience extreme scale on a dedicated serverless platform for Laravel. Sign up now!. Laravel Nova: The next generation of Nova is now available. Laravel Pulse: How's your health? Check your application's vital signs using Laravel Pulse. Laravel Reverb: You can easily build dynamic, real-time Laravel applications using WebSockets. Laravel Reverb is now available! * PROLOGUE * Release Notes * Upgrade Guide * Contribution Guide * SETUP * Installation * Configuration * Homestead * THE BASICS * Routing * Middleware * Controllers * Requests * Responses * Views * ARCHITECTURE FOUNDATIONS * Service Providers * Service Container * Contracts * Facades * Request Lifecycle * Application Structure * SERVICES * Authentication * Billing * Cache * Collections * Command Bus * Core Extension * Elixir * Encryption * Envoy * Errors & Logging * Events * Filesystem / Cloud Storage * Hashing * Helpers * Localization * Mail * Package Development * Pagination * Queues * Session * Templates * Unit Testing * Validation * DATABASE * Basic Usage * Query Builder * Eloquent ORM * Schema Builder * Migrations & Seeding * Redis * ARTISAN CLI * Overview * Development Version Master 11.x 10.x 9.x 8.x 7.x 6.x 5.8 5.7 5.6 5.5 5.4 5.3 5.2 5.1 5.0 4.2 SearchK > exclamation > > WARNING You're browsing the documentation for an old version of Laravel. > Consider upgrading your project to Laravel 11.x. MAIL * Configuration * Basic Usage * Embedding Inline Attachments * Queueing Mail * Mail & Local Development CONFIGURATION Laravel provides a clean, simple API over the popular SwiftMailer library. The mail configuration file is config/mail.php, and contains options allowing you to change your SMTP host, port, and credentials, as well as set a global from address for all messages delivered by the library. You may use any SMTP server you wish. If you wish to use the PHP mail function to send mail, you may change the driver to mail in the configuration file. A sendmail driver is also available. API DRIVERS Laravel also includes drivers for the Mailgun and Mandrill HTTP APIs. These APIs are often simpler and quicker than the SMTP servers. Both of these drivers require that the Guzzle 5 HTTP library be installed into your application. You can add Guzzle 5 to your project by adding the following line to your composer.json file: "guzzlehttp/guzzle": "~5.0" MAILGUN DRIVER To use the Mailgun driver, set the driver option to mailgun in your config/mail.php configuration file. Next, create an config/services.php configuration file if one does not already exist for your project. Verify that it contains the following options: 'mailgun' => [ 'domain' => 'your-mailgun-domain', 'secret' => 'your-mailgun-key', ], MANDRILL DRIVER To use the Mandrill driver, set the driver option to mandrill in your config/mail.php configuration file. Next, create an config/services.php configuration file if one does not already exist for your project. Verify that it contains the following options: 'mandrill' => [ 'secret' => 'your-mandrill-key', ], LOG DRIVER If the driver option of your config/mail.php configuration file is set to log, all e-mails will be written to your log files, and will not actually be sent to any of the recipients. This is primarily useful for quick, local debugging and content verification. BASIC USAGE The Mail::send method may be used to send an e-mail message: Mail::send('emails.welcome', ['key' => 'value'], function($message) { $message->to('foo@example.com', 'John Smith')->subject('Welcome!'); }); The first argument passed to the send method is the name of the view that should be used as the e-mail body. The second is the data to be passed to the view, often as an associative array where the data items are available to the view by $key. The third is a Closure allowing you to specify various options on the e-mail message. lightbulb A $message variable is always passed to e-mail views, and allows the inline embedding of attachments. So, it is best to avoid passing a message variable in your view payload. You may also specify a plain text view to use in addition to an HTML view: Mail::send(['html.view', 'text.view'], $data, $callback); Or, you may specify only one type of view using the html or text keys: Mail::send(['text' => 'view'], $data, $callback); You may specify other options on the e-mail message such as any carbon copies or attachments as well: Mail::send('emails.welcome', $data, function($message) { $message->from('us@example.com', 'Laravel'); $message->to('foo@example.com')->cc('bar@example.com'); $message->attach($pathToFile); }); When attaching files to a message, you may also specify a MIME type and / or a display name: $message->attach($pathToFile, ['as' => $display, 'mime' => $mime]); If you just need to e-mail a simple string instead of an entire view, use the raw method: Mail::raw('Text to e-mail', function($message) { $message->from('us@example.com', 'Laravel'); $message->to('foo@example.com')->cc('bar@example.com'); }); lightbulb The message instance passed to a Mail::send Closure extends the SwiftMailer message class, allowing you to call any method on that class to build your e-mail messages. EMBEDDING INLINE ATTACHMENTS Embedding inline images into your e-mails is typically cumbersome; however, Laravel provides a convenient way to attach images to your e-mails and retrieving the appropriate CID. EMBEDDING AN IMAGE IN AN E-MAIL VIEW <body> Here is an image: <img src="<?php echo $message->embed($pathToFile); ?>"> </body> EMBEDDING RAW DATA IN AN E-MAIL VIEW <body> Here is an image from raw data: <img src="<?php echo $message->embedData($data, $name); ?>"> </body> Note that the $message variable is always passed to e-mail views by the Mail facade. QUEUEING MAIL QUEUEING A MAIL MESSAGE Since sending e-mail messages can drastically lengthen the response time of your application, many developers choose to queue e-mail messages for background sending. Laravel makes this easy using its built-in unified queue API. To queue a mail message, simply use the queue method on the Mail facade: Mail::queue('emails.welcome', $data, function($message) { $message->to('foo@example.com', 'John Smith')->subject('Welcome!'); }); You may also specify the number of seconds you wish to delay the sending of the mail message using the later method: Mail::later(5, 'emails.welcome', $data, function($message) { $message->to('foo@example.com', 'John Smith')->subject('Welcome!'); }); If you wish to specify a specific queue or "tube" on which to push the message, you may do so using the queueOn and laterOn methods: Mail::queueOn('queue-name', 'emails.welcome', $data, function($message) { $message->to('foo@example.com', 'John Smith')->subject('Welcome!'); }); MAIL & LOCAL DEVELOPMENT When developing an application that sends e-mail, it's usually desirable to disable the sending of messages from your local or development environment. To do so, you may either call the Mail::pretend method, or set the pretend option in the config/mail.php configuration file to true. When the mailer is in pretend mode, messages will be written to your application's log files instead of being sent to the recipient. If you would like to actually view the test e-mails, consider using a service like MailTrap. How do passkeys increase user security and how can you use them? Find out in our free white paper ads via Carbon Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in most web projects. * * * * Highlights * Release Notes * Getting Started * Routing * Blade Templates * Authentication * Authorization * Artisan Console * Database * Eloquent ORM * Testing Resources * Laravel Bootcamp * Laracasts * Laravel News * Laracon * Laracon AU * Laracon EU * Laracon India * Larabelles * Careers * Jobs * Forums * Trademark Partners * Vehikl * WebReinvent * Tighten * Bacancy * 64 Robots * Active Logic * Black Airplane * Byte 5 * Curotec * Cyber-Duck * DevSquad * Jump24 * Kirschbaum Ecosystem * Breeze * Cashier * Dusk * Echo * Envoyer * Forge * Herd * Horizon * Inertia * Jetstream * Livewire * Nova * Octane * Pennant * Pint * Prompts * Pulse * Reverb * Sail * Sanctum * Scout * Socialite * Spark * Telescope * Vapor Laravel is a Trademark of Laravel Holdings Inc. Copyright © 2011-2024 Laravel Holdings Inc. Code highlighting provided by Torchlight