Hello everyone for your reply.
Using mailjet.com, I was able to send emails to localhost. Below are the various steps:
Step 1
Create an account on the mailjet website.
Step 2
In app.php, add a new entry to the EmailTransport table. Various host, port, username and password options can be found on the mailjet website.
'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, ], 'mailjet' => [ 'host' => 'in-v3.mailjet.com', 'port' => 587, 'timeout' => 60, 'username' => 'xxxxx', 'password' => 'xxxxx', 'className' => 'Smtp' ] ],
Step 3
In your controller
<?php namespace App\Controller; use App\Controller\AppController; use Cake\Network\Email\Email; class ContactController extends AppController { var $helpers = array('Html'); public function index(){ if($this->request->is('post')){ $userName = $this->request->data['firstname'] . " " . $this->request->data['lastname']; $email = new Email(); $email->transport('mailjet'); try { $res = $email->from([$this->request->data['email'] => $userName]) ->to([' myEmail@hotmail.com ' => 'My Website']) ->subject('Contact') ->send($this->request->data['message']); } catch (Exception $e) { echo 'Exception : ', $e->getMessage(), "\n"; } } }
source share