Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Configuring gmail in Cakephp 3

    • 0
    • 0
    • 0
    • 0
    • 2
    • 0
    • 2
    • 0
    • 2.43k
    Comment on it

    Configuring gmail in Cakephp 3.x

    Hello friends, welcome to findnerd. Today I am going to tell you how to configure gmail in cakephp 3.x. First of all you need to load the class for email in Controller:


    use Cake\Mailer\Email;


    Second step is to create configuration in config/app.php. Now to configure gmail in cakephp you need to set your className => Smtp, hostname => 'ssl://', port => 465, username and password of your gmail account. Write the following lines as shown below:


    'EmailTransport' => [
            'default' => [
                'className' => 'Smtp',
                // The following keys are used in SMTP transports
                'host' => 'ssl://',
                'port' => 465,
                'timeout' => 30,
                'username' => '',
                'password' => 'password@123',
                'client' => null,
                'tls' => null,
                'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),


    If you want to configure tls communication, then set tls => true

    Third step is to create template for email. Lets create welcome template at src/Template/html/welcome.ctp. You can write your welcome message on welcome.ctp file. 

    Next step to write function in the controller to send email:


    public function sendMail(){
           $email = new Email();
           $email->viewVars(['user' => ['username' => 'amukmca']]);


    If you get this error message: "SMTP server did not accept the password" as shown below:



    Then this issue can be resolved by turning on Access for less secure apps on Google. You can do it by logging in to your google account and clicking on this link


    For more information you can refer to this link:


    Thanks for reading the blog.

    Configuring gmail in Cakephp 3

 2 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: