Welcome to FindNerd. We are going to discuss the Email configurations in CakePHP 3. Every framework or CMS includes different functions and configurations for email management. CakePHP uses Email class inside Cake\Mailer. By using this class Email, you can send email from any controller.
You need to load the class Email in your application and then write the code to send the email. Please check below code to load the class.
use Cake\Mailer\Email;
After loading the class you can send the email like this
$my_email = new Email('default');
$my_email->from(['support@findnerd.com' => 'My FindNerd'])
->to('Users@gmail.com')
->subject('Great collections on FindNerd')
->send('Ready to enjoy the latest features only on FindNerd');
Email class provides different methods for different purposes. After creating the instance of the class we can call these methods. We have already used the methods such as subject(),to(),send() and from() in above code. There are many more methods like to(), cc(), bcc(), addCC(), addTo(), addBcc() etc. First three mentioned functions add the recipient as well as overwrite the already set recipients. Later three functions add more recipients after adding the recipient using first three functions. Please have a hook.
$my_email->to('Users@gmail.com'); // only one recepient
$my_email->addTo('Sub_users@gmail.com'); // Now added two recepients
$my_email->to('primary@gmail.com'); // overwrite above added recepients. Now recepient is primary@gmail.com
These are the basic functions available in Email class. In next blogs we will discuss other configurations as well.
Thanks for being with us!
0 Comment(s)