maurymmarques / postmark-cakephp

Postmark plugin for CakePHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Undefined index when using CakePHP logging

atomtigerzoo opened this issue · comments

When using

'log' => true

in my email config I get errors about undefined indexes 'headers' and 'message'

Notice (8): Undefined index: message [CORE/Cake/Network/Email/CakeEmail.php, line 1067]

I tried fixing this but cannot find out how to set both indexes required in the above line in CakeEmail.

Fixed.
Change in return send() method.
For operation log, now the data are not returned directly postmark.

// Before
$result = $email->send('Message');
print_r($result);
array(
        'To' => 'Recipient <recipient@domain.com>',
        'SubmittedAt' => '2012-07-31T10:21:03.2406-04:00',
        'MessageID' => 'ce289556-eeba-438d-9bf7-01cde05842fh',
        'ErrorCode' => (int) 0,
        'Message' => 'OK'
)
// Now
$result = $email->send('Message');
print_r($result);
'Postmark' => array(
        'To' => 'Recipient <recipient@domain.com>',
        'SubmittedAt' => '2012-07-31T10:21:03.2406-04:00',
        'MessageID' => 'ce289556-eeba-438d-9bf7-01cde05842fh',
        'ErrorCode' => (int) 0,
        'Message' => 'OK'
)

Thank you very much for your quick response & fix!

I discovered another bug in the fix. In line 82 you are using $message['HtmlBody'] which might not be present when only sending text emails. The following fixes it and only uses the HtmlBody when nothing else is present (better for the log file):

Line 82:

---- $message = $message['HtmlBody'];

++++ if($this->_cakeEmail->emailFormat() === 'text' || $this->_cakeEmail->emailFormat() === 'both') {
++++    $message = $message['TextBody'];
++++ }
++++ else{
++++    $message = $message['HtmlBody'];
++++ }

I hope the formatting is right and you understand what I'm saying :)

I did not change anything, only the indentation
Any improvement is welcome
Thanks

I think my comment has overlapped my fixes I sent in via pull-request. I made this comment before I got the idea to try and do my first clone/push/pullrequest :) So you can/could simply ignore this comment as it was fixed in my pull-request you merged.