开发者

Using CakePHP's Email component

开发者 https://www.devze.com 2022-12-08 21:09 出处:网络
I try to 开发者_如何转开发send a simple Email via CakePHP\'s Email Component. I\'m using following code from the cookbook documentation:

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 <irgendjemand@example.com>';
$this->Email->to      = 'Irgendjemand Anderes <irgendjemand.anderes@example.com>';
$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?


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'));


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'));
}


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 <someone@example.com>". 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消