0

With the code below my emails would send fine in dev mode. Now that I've put my App into production mode when I try to trigger one of the actions to send an email the page just loads and loads until I get the CakePHP error. The data still goes into the database however.

'EmailTransport' => [
    'default' => [
        'className' => 'Mail',
        // The following keys are used in SMTP transports
        'host' => 'localhost',
        'port' => 25,
        'timeout' => 30,
        'username' => 'user',
        'password' => 'secret',
        'client' => null,
        'tls' => null,
        'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
    ],
    'mailjet' => [
        'host' => 'in-v3.mailjet.com',
        'port' => 587,
        'timeout' => 60,
        'username' => 'removed',
        'password' => 'removed',
        'className' => 'Smtp'
    ],
],



public function register()
{
    $user = $this->Users->newEntity();

    if ($this->request->is('post')) {
        $user = $this->Users->patchEntity($user, $this->request->data);
        $user->role = 'user';
        $user->email_verified = '0';
        $user->email_token = Security::hash($user->username + microtime(), 'sha1', true);
        $user->email_token_expires = strtotime('now');
        $user->email_token_expires = strtotime('+1 hour');

        if ($result = $this->Users->save($user)) {
            $this->Users->lastLogin($user['id']);
            $authUser = $this->Users->get($result->id)->toArray();
            $this->Auth->setUser($authUser);

            $email = new Email();
            $email->template('confirm')
                    ->transport('mailjet')
                    ->emailFormat('both')
                    ->viewVars(['token' => $user->email_token])
                    ->to($this->Auth->user('email'))
                    ->from(['removed' => 'Welcome, ' . $user->username . '!'])
                    ->subject('Please confirm your email!')
                    ->send();

            $this->Flash->success('You have successfully registered. Check your email to confirm email.');
            return $this->redirect(['action' => 'profile']);
        } else {
            $this->Flash->error('The user could not be saved. Please, try again.');
        }
    }
    $this->set(compact('user', 'userEmail', 'token'));
    $this->set('_serialize', ['user']);
}

What could it be?

Error:

Connection timed out
Cake\Network\Exception\SocketException
  • 1
    _loads until I get the CakePHP error._ what does it say? What does the error log say? – Sevvlor May 07 '16 at 20:12
  • An Internal Error Has Occurred Error: An Internal Error Has Occurred. – user3617311 May 07 '16 at 20:22
  • Connection timed out Cake\Network\Exception\SocketException – user3617311 May 07 '16 at 20:29
  • Then you need to verify if you _can_ connect to the SMTP server from your production server. This might help you a little further in de bugging http://stackoverflow.com/a/11988455/1604068 – Sevvlor May 07 '16 at 20:30
  • I've added my domain to the mailjet settings which I thought would fix it. Apparently not – user3617311 May 07 '16 at 21:06
  • _Connection timed out_ implies that the connection between your server and the Mailjet server timed out. Could be caused by E.g. Bad port, firewall etc – Sevvlor May 07 '16 at 21:12
  • All ports are open on the server that mailjet uses – user3617311 May 07 '16 at 22:44
  • 1
    StackOverflow is not a debugging service, SO is about specific programming related problems, you have to check on your own what's going on with your server environment. Your question _may_ fit on serverfault, given that you'd provide more context information. – ndm May 08 '16 at 11:19
  • did you configure php.ini on the production server? – rameshpa May 09 '16 at 20:05

1 Answers1

0

Last time I got this error, the smtp address was blocked in my production server.

After whitelisting the smtp address everything was fine.