PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 14, 2022

[FIXED] Sending Mail using CakePHP 3.0

 January 14, 2022     cakephp, email     No comments   

Issue

I am developing a website with new version 3.0 of CakePHP Framework. I am working on localhost and would like to send an email after a user has filled a form. Below is the code in my controller to send the email.

public function index(){
    if ($this->request->is('post'){
       $email = new Email();
       $email->from([$this->request->data["sender"] => "Sender"]
             ->to("myEmail@hotmail.com")
             ->subject($this->request->data["Subject"])
             ->send($this->request->data["message"]);
    }
}

When this code is executed nothing happen, no error, no message in my mailbox. I have seen that it exist in cakephp3.0 a class called DebugTransport but I don't know how to use it in order to debug my code. Someone has already use it ?


Solution

You had to use a SMTP server for delivery your email from your localhost in your config email.

There are 2 ways to achieve this:

  1. Use it from a real server with a mail configuration

  2. Use SMTP server for your test on your localhost. there are a lot of SMTP server with let you use it. see mailjet.com



Answered By - MouradK
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing