Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel mail pretend prints nothing

Tags:

php

email

laravel

I set 'pretend' => true, in the mail.php, created this new.php view:

<body>     <div>         E-mail: {{ $user->email }}<br>         User: {{ $user->username }}<br>         Pass: {{ $user->password }}<br>     </div> </body> 

Then in my controller I use this code to "send" the mail:

$data['user'] = $user; Mail::send('emails.new', $data, function($message) use ($user) {     $message->to('[email protected]', $user->username)->subject('Account'); }); 

The output in the log file is only this:

[2013-08-30 11:27:56] log.INFO: Pretending to mail message to: [email protected] [] []

I tried with a full HTML view, also with another view that contains only strings, no variables, but the output is the same.

Is this the way how this should work? Shouldn't it print the whole message, title, etc? Is there a problem with the code or this is the proper output?

like image 810
totymedli Avatar asked Aug 30 '13 11:08

totymedli


2 Answers

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: [email protected] [] [] 

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: <[email protected]>  Date: Thu, 17 Jul 2014 14:15:15 +0000  Subject: Welcome! From: Ahmad <[email protected]> To: John Smith <[email protected]> MIME-Version: 1.0 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable       Order confirmed!   [] [] 
like image 166
Daniel A.A. Pelsmaeker Avatar answered Sep 20 '22 02:09

Daniel A.A. Pelsmaeker


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.

like image 31
sirtimbly Avatar answered Sep 21 '22 02:09

sirtimbly