I set \'pretend\' => true,
in the mail.php
, created this new.php
view:
E-mail: {{
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 +0000
Subject: Welcome!
From: Ahmad <ahmad@example.com>
To: John Smith <foo@example.com>
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Order confirmed!
[] []
I created a package to also include subject and body for laravel 4.2.
The package can be found here: https://packagist.org/packages/peercode/mail
Just enable the package as descripted here: https://github.com/peercode-eric/laravel-maillog and the log will contain the additional information.
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.
I include this in my send callbacks:
Mail::send(array('emails.html','emails.text'),$data,function($message) use($data)
{
//Set $message data
if(Config::get('mail.pretend')) Log::info(View::make('emails.html',$data)->render());
}
Alternately, you can pass the views render into another view to see the html rendered in your browser.
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}");
}