views:

522

answers:

3

Hi!

I try to send a simple Email via CakePHP's Email Component. I'm using following code from the cookbook documentation:

$this->Email->from    = 'Irgendjemand <[email protected]>';
$this->Email->to      = 'Irgendjemand Anderes <[email protected]>';
$this->Email->subject = 'Test';
$this->Email->send('Dies ist der Nachrichtenrumpf!');

The send()-method does only return a boolean value with the value false - but no error or warning occurs.

Does somebody have a solution for that?

A: 

Have you tried changing the delivery options? There are three options: mail, smtp and debug.

$this->Email->delivery = 'debug';
$this->Email->send('test message');
debug($this->Session->read('Message.email'));
deizel
A: 

Which OS are you on? If Windows, this note may be of interest:

Note: The Windows implementation of mail() differs in many ways from the Unix implementation.
...
As such, the to parameter should not be an address in the form of
"Something <[email protected]>". The mail command may not parse this properly while talking with the MTA.

Secondly, it may just be the case that no mail server will accept outgoing mail from your local machine due to spam protection. I have often seen that the same mail() function will not work locally, but works fine once uploaded to a trustworthy server. You could try to use an authenticated mail relay in that case (SMTP).

deceze
+1  A: 

You can debug with EMail. Set the delivery to debug and the email message will be set to Session.message:

if (Configure::read('debug') > 1) {
    $this->Email->delivery = 'debug';
}
$ret = $this->Email->send();
if (Configure::read('debug') > 1) {
    pr($this->Session->read('Message.email'));
}
Primeminister