user606521
user606521

Reputation: 15434

cake php email helper - internal error

I am trying to send email with cake php email component:

var $components = array('Email');

$email = new CakeEmail();
$email->from(array('[email protected]' => 'My Site'));
$email->to('[email protected]');
$email->subject('About');
$email->send('My message');

And I always get message: Couldnt send email. Internal error occured. In error log there is "SocketException".

I am using cakephp 2.0.

How should I configure things to get it work? I don't want to use any smtp servers and so on, I just want to send simple email.

I am using WAMP on my PC.

Upvotes: 0

Views: 4511

Answers (3)

Borislav Sabev
Borislav Sabev

Reputation: 4856

This really does look like it's an error with your mail server setup or the connection to it. However, you are confusing the CakeEmail class for the EmailComponent.

Firstly you're not trying to send a email with the emailComponent, you are using the new CakeMail class (new from 2.x). Thus, this:

var $components = array('Email');

and this:

$email = new CakeEmail();

are two different things. The first loads the EmailComponent, but you're not using it at all. The EmailComponent as of 2.x is deprecated. In your example you're using the CakeEmail Class.

Firstly you should insure that the class is actually loaded:

App::uses('CakeEmail', 'Network/Email');

Then check if you have the configuration file in:

App/Config/email.php

I suppose you're currently using the default configuration option. This means that the default transport is 'Mail' - the PHP mail function. I suppose you're getting a SocketException, because it can't connect to a underlying mail transport agent and because it is trying to do so over a System Socket... (Which I do not think exists in Windows, but I could be wrong. I know for sure that there is something like that in the windows API for inter-process cominucation)

Anyway, using the default email configuration is ok. Read the CakePHP Book's Section on the CakeEmail class.

Upvotes: 1

anasanjaria
anasanjaria

Reputation: 1308

Uncomment the line: extension=php_openssl.dll in php.ini. This will resolve your Socket problem.

One more thing I want to say is :

You are mixing two thing core library & component both. FYI

EmailComponent is now deprecated. so use core library instead.

for more details check this link http://book.cakephp.org/2.0/en/core-utility-libraries/email.html

Upvotes: 2

floriank
floriank

Reputation: 25698

Debug the exception.

I bet that you can't open a connection to your mail server. Looks more like it's an error with your mail server setup or the connection to it than with CakePHp.

For an easy mail server setup for windows I recommend you to use XAMPP, it comes with the preconfigured mail server Pegasus, works just easy and fast for me.

Upvotes: 1

Related Questions