PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, December 31, 2021

[FIXED] How to use email transport class "Debug" in CakePHP 3

 December 31, 2021     cakephp-3.0     No comments   

Issue

How can I view the result (final mail) with the email transport class "Debug" in CakePHP 3? Or where can I find the returned result? There's no detailled information about email debugging in the book.

In config/app.php it says

// Each transport needs a `className`. Valid options are as follows:
// - Mail  : Send using PHP mail function
// - Smtp  : Send using SMTP
// - Debug : Do not send the email, just return the result

So I set

'EmailTransport' => [
  'default' => [
    'className' => 'Debug',
  ],
],

And in a test controller:

namespace App\Controller;
use App\Controller\AppController;
use Cake\Event\Event;
use Cake\Network\Exception\NotFoundException;
use Cake\Mailer\Email;

class TestsController extends AppController {
  public function email_test() {
    $email = new Email('default');
    $email->from(['website@example.com' => 'My Site'])
          ->to('destination@example.com')
          ->subject('Here the subject')
          ->send('Here the mail content'));
  }
}

But where is the result (final mail) saved or shown?

I expected the Debug result in /tmp/ or /logs/ but could't find any information about the final mail there.

If I view the testpage in Browser (localhost/test/email_test/) nothing is displayed (as I don't know what to add in the view template for email debugging). There's also no information about the mail in the CakePHP-DebugKit...

(I'm currently testing this with CakePHP 3.1 beta if that is relevant)


Solution

The result is being returned by the Email::send() method. It always returns the mail content, it's just that the Debug transport doesn't actually send it.

$result = $email->...->send('Here the mail content');
debug($result);

https://github.com/cakephp/.../3.1.0-beta2/src/Mailer/Transport/DebugTransport.php#L36

Some more details in the docs wouldn't hurt I guess.

If you'd wanted to have the mails logged, you'd have to enable/configure logging in the transport configuration using the log option. By default it is set to false.

'log': Log level to log the email headers and message. true will use LOG_DEBUG

Cookbook > Email > Configuration Profiles



Answered By - ndm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing