Laravel mail pretend prints nothing Laravel mail pretend prints nothing laravel laravel

Laravel mail pretend prints nothing


If you set 'pretend' => true in app/config/mail.php then no mail is ever sent, you get just a message in the log, like this:

[2014-07-17 14:15:07] production.INFO:    Pretending to mail message to: foo@example.com [] []

However, if you leave 'pretend' => false and instead use the log driver ('driver' => 'log', available since Laravel 4.2), then instead of sending the mail, you'll get the whole mail content written into the log:

[2014-07-17 14:15:14] production.DEBUG:    Message-ID: <da39a3ee5e6b4b0d3255bfef95601890@example.com>Date: Thu, 17 Jul 2014 14:15:15 +0000Subject: Welcome!From: Ahmad <ahmad@example.com>To: John Smith <foo@example.com>MIME-Version: 1.0Content-Type: text/html; charset=utf-8Content-Transfer-Encoding: quoted-printable    Order confirmed! [] []


If you actually want to view the contents of the message (for instance when testing user account verification or password reset emails) in the /storage/logs logfile; You can modify your local copy of vendor/laravel/framework/src/Illuminate/Mail/Mailer.php and in the logMessages function modify it to look like

protected function logMessage($message){    $emails = implode(', ', array_keys((array) $message->getTo()));    $body = $message->getBody();    $this->logger->info("Pretending to mail message to: {$emails} :-: {$body}");}

Then you will see the body of the message in the logs.


This is the normal behaviour of pretend in the Laravel Mailer system. It will not render your message anywhere, not even in the log, it will just log that a mail message was pretended to be sent. Look at the related source code:

/** * Send a Swift Message instance. * * @param  Swift_Message  $message * @return void */protected function sendSwiftMessage($message){    if ( ! $this->pretending)    {        return $this->swift->send($message);    }    elseif (isset($this->logger))    {        $this->logMessage($message);    }}/** * Log that a message was sent. * * @param  Swift_Message  $message * @return void */protected function logMessage($message){    $emails = implode(', ', array_keys($message->getTo()));    $this->logger->info("Pretending to mail message to: {$emails}");}