Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot send email #151

Closed
ronnyharianto opened this issue Oct 16, 2017 · 8 comments
Closed

Cannot send email #151

ronnyharianto opened this issue Oct 16, 2017 · 8 comments

Comments

@ronnyharianto
Copy link

Hope that I can get answer here
I have already install a new cakephp dan cakephp-queue on my machine. But it didn't work when queueworker send the email.

I always get this error :

2017-10-16 07:08:44 Warning: Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'Cake\Mailer\Email' does not have a method 'viewConfig' in [D:\xampp\htdocs\e-commerce\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110]
Trace:
Cake\Error\BaseErrorHandler::handleError() - CORE\src\Error\BaseErrorHandler.php, line 153
Queue\Shell\Task\QueueEmailTask::run() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110
Queue\Shell\QueueShell::runworker() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\QueueShell.php, line 169
Cake\Console\Shell::runCommand() - CORE\src\Console\Shell.php, line 494
Cake\Console\CommandRunner::run() - CORE\src\Console\CommandRunner.php, line 141
[main] - ROOT\bin\cake.php, line 12

2017-10-16 07:08:44 Warning: Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'Cake\Mailer\Email' does not have a method '_to' in [D:\xampp\htdocs\e-commerce\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110]
Trace:
Cake\Error\BaseErrorHandler::handleError() - CORE\src\Error\BaseErrorHandler.php, line 153
Queue\Shell\Task\QueueEmailTask::run() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110
Queue\Shell\QueueShell::runworker() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\QueueShell.php, line 169
Cake\Console\Shell::runCommand() - CORE\src\Console\Shell.php, line 494
Cake\Console\CommandRunner::run() - CORE\src\Console\CommandRunner.php, line 141
[main] - ROOT\bin\cake.php, line 12

2017-10-16 07:08:44 Warning: Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'Cake\Mailer\Email' does not have a method '_from' in [D:\xampp\htdocs\e-commerce\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110]
Trace:
Cake\Error\BaseErrorHandler::handleError() - CORE\src\Error\BaseErrorHandler.php, line 153
Queue\Shell\Task\QueueEmailTask::run() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110
Queue\Shell\QueueShell::runworker() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\QueueShell.php, line 169
Cake\Console\Shell::runCommand() - CORE\src\Console\Shell.php, line 494
Cake\Console\CommandRunner::run() - CORE\src\Console\CommandRunner.php, line 141
[main] - ROOT\bin\cake.php, line 12

2017-10-16 07:08:44 Warning: Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'Cake\Mailer\Email' does not have a method '_subject' in [D:\xampp\htdocs\e-commerce\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110]
Trace:
Cake\Error\BaseErrorHandler::handleError() - CORE\src\Error\BaseErrorHandler.php, line 153
Queue\Shell\Task\QueueEmailTask::run() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110
Queue\Shell\QueueShell::runworker() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\QueueShell.php, line 169
Cake\Console\Shell::runCommand() - CORE\src\Console\Shell.php, line 494
Cake\Console\CommandRunner::run() - CORE\src\Console\CommandRunner.php, line 141
[main] - ROOT\bin\cake.php, line 12

2017-10-16 07:08:44 Warning: Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'Cake\Mailer\Email' does not have a method '_emailFormat' in [D:\xampp\htdocs\e-commerce\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110]
Trace:
Cake\Error\BaseErrorHandler::handleError() - CORE\src\Error\BaseErrorHandler.php, line 153
Queue\Shell\Task\QueueEmailTask::run() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110
Queue\Shell\QueueShell::runworker() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\QueueShell.php, line 169
Cake\Console\Shell::runCommand() - CORE\src\Console\Shell.php, line 494
Cake\Console\CommandRunner::run() - CORE\src\Console\CommandRunner.php, line 141
[main] - ROOT\bin\cake.php, line 12

2017-10-16 07:08:44 Warning: Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'Cake\Mailer\Email' does not have a method '_emailPattern' in [D:\xampp\htdocs\e-commerce\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110]
Trace:
Cake\Error\BaseErrorHandler::handleError() - CORE\src\Error\BaseErrorHandler.php, line 153
Queue\Shell\Task\QueueEmailTask::run() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110
Queue\Shell\QueueShell::runworker() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\QueueShell.php, line 169
Cake\Console\Shell::runCommand() - CORE\src\Console\Shell.php, line 494
Cake\Console\CommandRunner::run() - CORE\src\Console\CommandRunner.php, line 141
[main] - ROOT\bin\cake.php, line 12

2017-10-16 07:08:44 Warning: Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'Cake\Mailer\Email' does not have a method '_domain' in [D:\xampp\htdocs\e-commerce\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110]
Trace:
Cake\Error\BaseErrorHandler::handleError() - CORE\src\Error\BaseErrorHandler.php, line 153
Queue\Shell\Task\QueueEmailTask::run() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110
Queue\Shell\QueueShell::runworker() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\QueueShell.php, line 169
Cake\Console\Shell::runCommand() - CORE\src\Console\Shell.php, line 494
Cake\Console\CommandRunner::run() - CORE\src\Console\CommandRunner.php, line 141
[main] - ROOT\bin\cake.php, line 12

2017-10-16 07:08:44 Warning: Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'Cake\Mailer\Email' does not have a method '_messageId' in [D:\xampp\htdocs\e-commerce\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110]
Trace:
Cake\Error\BaseErrorHandler::handleError() - CORE\src\Error\BaseErrorHandler.php, line 153
Queue\Shell\Task\QueueEmailTask::run() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110
Queue\Shell\QueueShell::runworker() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\QueueShell.php, line 169
Cake\Console\Shell::runCommand() - CORE\src\Console\Shell.php, line 494
Cake\Console\CommandRunner::run() - CORE\src\Console\CommandRunner.php, line 141
[main] - ROOT\bin\cake.php, line 12

2017-10-16 07:08:44 Warning: Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'Cake\Mailer\Email' does not have a method '_appCharset' in [D:\xampp\htdocs\e-commerce\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110]
Trace:
Cake\Error\BaseErrorHandler::handleError() - CORE\src\Error\BaseErrorHandler.php, line 153
Queue\Shell\Task\QueueEmailTask::run() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php, line 110
Queue\Shell\QueueShell::runworker() - ROOT\vendor\dereuromark\cakephp-queue\src\Shell\QueueShell.php, line 169
Cake\Console\Shell::runCommand() - CORE\src\Console\Shell.php, line 494
Cake\Console\CommandRunner::run() - CORE\src\Console\CommandRunner.php, line 141
[main] - ROOT\bin\cake.php, line 12

2017-10-16 07:08:44 Error: QueueEmail
BadMethodCallException: You need specify one destination on to, cc or bcc.
#0 D:\xampp\htdocs\e-commerce\vendor\dereuromark\cakephp-queue\src\Shell\Task\QueueEmailTask.php(126): Cake\Mailer\Email->send(NULL)
#1 D:\xampp\htdocs\e-commerce\vendor\dereuromark\cakephp-queue\src\Shell\QueueShell.php(169): Queue\Shell\Task\QueueEmailTask->run(Array, 8)
#2 D:\xampp\htdocs\e-commerce\vendor\cakephp\cakephp\src\Console\Shell.php(494): Queue\Shell\QueueShell->runworker()
#3 D:\xampp\htdocs\e-commerce\vendor\cakephp\cakephp\src\Console\CommandRunner.php(141): Cake\Console\Shell->runCommand(Array, true)
#4 D:\xampp\htdocs\e-commerce\bin\cake.php(12): Cake\Console\CommandRunner->run(Array)
#5 {main}

@dereuromark
Copy link
Owner

How did you add a job? You need to paste your code here and the data you are passing to it.

@stmeyer
Copy link
Contributor

stmeyer commented Oct 19, 2017

I've the same error. Configuration:

    'EmailTransport' => [
        'default' => [
            'className' => 'Smtp',
            // The following keys are used in SMTP transports
            'host' => 'host',
            'port' => 25,
            'timeout' => 30,
            'username' => 'user',
            'password' => 'secret',
            'client' => null,
            'tls' => null,
        ],
        'queue' => [
            'className' => 'Queue.Queue',
            'transport' => 'default'
        ],
    ],
    'Email' => [
        'default' => [
            'transport' => 'queue',
            'from' => 'mail@example.com',
            'charset' => 'utf-8',
            'headerCharset' => 'utf-8',
        ],
    ],

Send an E-Mail in a controller:

        $email = new \Cake\Mailer\Email('default');
        $email->from(['mail@example.com' => 'Example'])
            ->to('mail@example.com')
            ->subject('About')
            ->send('My message');

The $data in method run

public function run(array $data, $jobId) {
has the content:

[
        'transport' => 'default',
        'settings' => [
                'viewConfig' => [
                        '_layout' => 'default',
                        '_className' => 'Cake\View\View',
                        '_helpers' => [
                                (int) 0 => 'Html'
                        ]
                ],
                '_to' => [
                        'mail@example.com' => 'mail@example.com'
                ],
                '_from' => [
                        'mail@example.com' => 'Example'
                ],
                '_subject' => 'About',
                '_emailFormat' => 'text',
                '_emailPattern' => '/^((?:[\p{L}0-9.!#$%&'*+\/=?^_`{|}~-]+)*@[\p
{L}0-9-.]+)$/ui',
                '_domain' => '******',
                '_messageId' => true,
                '_appCharset' => 'UTF-8',
                'charset' => 'utf-8',
                'headerCharset' => 'utf-8'
        ]
]

@dereuromark
Copy link
Owner

Do you have an idea of a fix as PR?

@stmeyer
Copy link
Contributor

stmeyer commented Oct 19, 2017

I think it is because of commit 7ab4d15 "Use json_encode() instead of serialize". JSON can not be converted back to an PHP object. Instead of it is always converted into an array. And the line

if (is_object($email) && $email instanceof Email) {
checks for an object that could not be found

What was the reason to switch from serialize to json_encode?

@dereuromark
Copy link
Owner

Maybe also security issue I think?
But the actual main issue is any change to Email object would also not serialize it back.
So if you update your vendor (core) you would otherwise need to make sure the queue is empty.

Is there a way to jeep json_encode() and provide a mapping here for the option/config setting etc?

@stmeyer
Copy link
Contributor

stmeyer commented Oct 19, 2017

At the moment I do not see another way than reading out every configuration by calling all getters in QueueTransport into an array and writing this array into the database. In QueueEmailTask every configuration has to be written into the mail by calling all getters.

I tried something with get_class_methods but some getters form Email-class have parameters sothat I think it has to be done manually.

Or has anyone an other idea?

@dereuromark
Copy link
Owner

We can also switch back to the serialize then for the time being. Please make a PR.

dereuromark pushed a commit that referenced this issue Oct 20, 2017
Use serialize() instead of json_encode() again.
@stmeyer
Copy link
Contributor

stmeyer commented Oct 20, 2017

Working fine now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants