master

laravel/framework

Last updated at: 29/12/2023 09:25

Mail.php

TLDR

The provided file Mail.php is a facade class that allows you to access methods for managing email in Laravel.

Methods

fake

This method replaces the actual mail manager with a fake mail manager for testing purposes.

Classes

Mail

This facade class provides static methods for managing email in Laravel. It extends the Facade class and provides access to the following methods:

  • mailer - Retrieves the mailer instance for a given name or the default mailer
  • driver - Sets the default mail driver or retrieves the mail driver instance
  • createSymfonyTransport - Creates a Symfony transport instance for the given configuration
  • getDefaultDriver - Retrieves the default mail driver
  • setDefaultDriver - Sets the default mail driver
  • purge - Clears all resolved mailers or clears a specific mailer by name
  • extend - Extends the specified mail driver with a callback function
  • getApplication - Retrieves the application instance
  • setApplication - Sets the application instance
  • forgetMailers - Forgets all resolved mailers
  • alwaysFrom - Sets the global "from" address and name for all outgoing mail
  • alwaysReplyTo - Sets the global "reply to" address and name for all outgoing mail
  • alwaysReturnPath - Sets the global "return path" address for all outgoing mail
  • alwaysTo - Sets the global "to" address and name for all outgoing mail
  • to - Starts creating a new mail message with recipients
  • cc - Adds recipients to the "cc" list of a mail message
  • bcc - Adds recipients to the "bcc" list of a mail message
  • html - Sends a raw html email
  • raw - Sends a raw text email
  • plain - Renders a plain text email with a view and data and sends it
  • render - Renders a view to a string
  • send - Sends a mailable email or view with data
  • queue - Queues a mailable email or view with data for sending later
  • onQueue - Sets the queue for a queued mailable email
  • queueOn - Sets the queue for a queued mailable email
  • later - Sends a mailable email or view with data after a delay
  • laterOn - Sends a mailable email or view with data after a delay, using a specific queue
  • getSymfonyTransport - Retrieves the Symfony mail transport instance
  • getViewFactory - Retrieves the view factory instance
  • setSymfonyTransport - Sets the Symfony mail transport instance
  • setQueue - Sets the queue factory instance for the mailer
  • macro - Extends the Mail class with a new macro method
  • mixin - Mixes a class into the Mail class
  • hasMacro - Checks if the Mail class has a specific macro
  • flushMacros - Clears all registered macros
  • assertSent - Asserts that an email was sent
  • assertNotOutgoing - Asserts that an email was not sent
  • assertNotSent - Asserts that an email was not sent
  • assertNothingOutgoing - Asserts that no emails were sent
  • assertNothingSent - Asserts that no emails were sent
  • assertQueued - Asserts that an email was queued
  • assertNotQueued - Asserts that an email was not queued
  • assertNothingQueued - Asserts that no emails were queued
  • assertSentCount - Asserts the number of sent emails
  • assertQueuedCount - Asserts the number of queued emails
  • assertOutgoingCount - Asserts the number of outgoing emails
  • sent - Retrieves a collection of sent emails
  • hasSent - Checks if an email was sent
  • queued - Retrieves a collection of queued emails
  • hasQueued - Checks if an email was queued

Classes

  • Facades\Mail - This class extends the Illuminate\Support\Facade class and provides access to the facade methods for managing email in Laravel.
<?php

namespace Illuminate\Support\Facades;

use Illuminate\Support\Testing\Fakes\MailFake;

/**
 * @method static \Illuminate\Contracts\Mail\Mailer mailer(string|null $name = null)
 * @method static \Illuminate\Mail\Mailer driver(string|null $driver = null)
 * @method static \Symfony\Component\Mailer\Transport\TransportInterface createSymfonyTransport(array $config)
 * @method static string getDefaultDriver()
 * @method static void setDefaultDriver(string $name)
 * @method static void purge(string|null $name = null)
 * @method static \Illuminate\Mail\MailManager extend(string $driver, \Closure $callback)
 * @method static \Illuminate\Contracts\Foundation\Application getApplication()
 * @method static \Illuminate\Mail\MailManager setApplication(\Illuminate\Contracts\Foundation\Application $app)
 * @method static \Illuminate\Mail\MailManager forgetMailers()
 * @method static void alwaysFrom(string $address, string|null $name = null)
 * @method static void alwaysReplyTo(string $address, string|null $name = null)
 * @method static void alwaysReturnPath(string $address)
 * @method static void alwaysTo(string $address, string|null $name = null)
 * @method static \Illuminate\Mail\PendingMail to(mixed $users, string|null $name = null)
 * @method static \Illuminate\Mail\PendingMail cc(mixed $users, string|null $name = null)
 * @method static \Illuminate\Mail\PendingMail bcc(mixed $users, string|null $name = null)
 * @method static \Illuminate\Mail\SentMessage|null html(string $html, mixed $callback)
 * @method static \Illuminate\Mail\SentMessage|null raw(string $text, mixed $callback)
 * @method static \Illuminate\Mail\SentMessage|null plain(string $view, array $data, mixed $callback)
 * @method static string render(string|array $view, array $data = [])
 * @method static \Illuminate\Mail\SentMessage|null send(\Illuminate\Contracts\Mail\Mailable|string|array $view, array $data = [], \Closure|string|null $callback = null)
 * @method static mixed queue(\Illuminate\Contracts\Mail\Mailable|string|array $view, string|null $queue = null)
 * @method static mixed onQueue(string $queue, \Illuminate\Contracts\Mail\Mailable $view)
 * @method static mixed queueOn(string $queue, \Illuminate\Contracts\Mail\Mailable $view)
 * @method static mixed later(\DateTimeInterface|\DateInterval|int $delay, \Illuminate\Contracts\Mail\Mailable $view, string|null $queue = null)
 * @method static mixed laterOn(string $queue, \DateTimeInterface|\DateInterval|int $delay, \Illuminate\Contracts\Mail\Mailable $view)
 * @method static \Symfony\Component\Mailer\Transport\TransportInterface getSymfonyTransport()
 * @method static \Illuminate\Contracts\View\Factory getViewFactory()
 * @method static void setSymfonyTransport(\Symfony\Component\Mailer\Transport\TransportInterface $transport)
 * @method static \Illuminate\Mail\Mailer setQueue(\Illuminate\Contracts\Queue\Factory $queue)
 * @method static void macro(string $name, object|callable $macro)
 * @method static void mixin(object $mixin, bool $replace = true)
 * @method static bool hasMacro(string $name)
 * @method static void flushMacros()
 * @method static void assertSent(string|\Closure $mailable, callable|int|null $callback = null)
 * @method static void assertNotOutgoing(string|\Closure $mailable, callable|null $callback = null)
 * @method static void assertNotSent(string|\Closure $mailable, callable|null $callback = null)
 * @method static void assertNothingOutgoing()
 * @method static void assertNothingSent()
 * @method static void assertQueued(string|\Closure $mailable, callable|int|null $callback = null)
 * @method static void assertNotQueued(string|\Closure $mailable, callable|null $callback = null)
 * @method static void assertNothingQueued()
 * @method static void assertSentCount(int $count)
 * @method static void assertQueuedCount(int $count)
 * @method static void assertOutgoingCount(int $count)
 * @method static \Illuminate\Support\Collection sent(string|\Closure $mailable, callable|null $callback = null)
 * @method static bool hasSent(string $mailable)
 * @method static \Illuminate\Support\Collection queued(string|\Closure $mailable, callable|null $callback = null)
 * @method static bool hasQueued(string $mailable)
 *
 * @see \Illuminate\Mail\MailManager
 * @see \Illuminate\Support\Testing\Fakes\MailFake
 */
class Mail extends Facade
{
    /**
     * Replace the bound instance with a fake.
     *
     * @return \Illuminate\Support\Testing\Fakes\MailFake
     */
    public static function fake()
    {
        $actualMailManager = static::isFake()
                ? static::getFacadeRoot()->manager
                : static::getFacadeRoot();

        return tap(new MailFake($actualMailManager), function ($fake) {
            static::swap($fake);
        });
    }

    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor()
    {
        return 'mail.manager';
    }
}