简体   繁体   English

使用CakePHP的电子邮件组件

[英]Using CakePHP's Email component

I try to send a simple Email via CakePHP's Email Component. 我尝试通过CakePHP的电子邮件组件发送一个简单的电子邮件。 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. send()方法仅返回值为false的布尔值-但不会发生错误或警告。

Does somebody have a solution for that? 有人对此有解决方案吗?

Have you tried changing the delivery options? 您是否尝试过更改送货方式? There are three options: mail , smtp and debug . 共有三个选项: mailsmtpdebug

$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: 将传递设置为调试,电子邮件将设置为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: 如果是Windows, 可能需要注意以下事项

Note: The Windows implementation of mail() differs in many ways from the Unix implementation. 注意: mail()的Windows实现与Unix实现在很多方面有所不同。
... ...
As such, the to parameter should not be an address in the form of 因此,to参数不应是以下形式的地址:
" Something <someone@example.com> ". Something <someone@example.com> ”。 The mail command may not parse this properly while talking with the MTA. 与MTA交谈时,mail命令可能无法正确解析此命令。

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. 我经常看到相同的mail()函数在本地不起作用,但是一旦上载到可信赖的服务器,它就可以正常工作。 You could try to use an authenticated mail relay in that case (SMTP). 在这种情况下,您可以尝试使用经过身份验证的邮件中继(SMTP)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM