cytsunny
cytsunny

Reputation: 5030

Cakephp email official example not working?

I am new to Cakephp (and I have asked a few question on Cakephp here recently) and I am learning by trying out the example on the official site. The following is the link.

http://book.cakephp.org/2.0/en/core-utility-libraries/email.html

I added the to my Posts controller which I created before following the official example code.

public function emailTesting(){
    $Email = new CakeEmail();
    $Email->config('default');
    $Email->from(array('[email protected]' => 'My Site'));
    $Email->to('[email protected]');
    $Email->subject('Testing Subject');
    $Email->send('Testing email content');
}

According to the configuration section,

It is not required to create app/Config/email.php, CakeEmail can be used without it and use respective methods to set all configurations separately or load an array of configs.

So, I think the above code should work even if I don't create app/Config/email.php. Then,when I try to open the page

http://localhost/cakephpTesting/emailTesting/

It gives a blank page with no error message (the debug is already 2, which should shows all kind of error message if there is any error) but I didn't receive any email. I also tried different email service provider like Yahoo and my school email. All of them fails, so I think it should be the problem of my code?

So, anybody got any idea on what have I missed?

Upvotes: 0

Views: 99

Answers (1)

jimmymadon
jimmymadon

Reputation: 612

As mentioned in your question, it is not required to create a app/Config/email.php, IF you use respective methods to set all configurations separately or load an array of configs.

You are using Email::config() method to load a $default config array which is supposed to be defined somewhere. As good practise, it can be defined in the app/Config/email.php or define it in your controller's action (don't recommend the latter). CakeEmail needs to know the transport type, host, port, etc.

Read the section after the line that you have mentioned in your question which tells you how to either use the constructor of CakeEmail or use the $config array.

Upvotes: 3

Related Questions