简体   繁体   English

Cakephp电子邮件官方示例不起作用?

[英]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. 我是Cakephp的新手(最近我在这里对Cakephp提出了一些问题),并且通过在官方网站上尝试该示例来学习。 The following is the link. 以下是链接。

http://book.cakephp.org/2.0/en/core-utility-libraries/email.html 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. 我在遵循正式的示例代码之前,将其添加到我创建的Posts控制器中。

public function emailTesting(){
    $Email = new CakeEmail();
    $Email->config('default');
    $Email->from(array('me@example.com' => 'My Site'));
    $Email->to('myWorkingEmail@gmail.com');
    $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. 不需要创建app / Config / email.php,CakeEmail可以在没有它的情况下使用,并且可以使用各自的方法分别设置所有配置或加载配置数组。

So, I think the above code should work even if I don't create app/Config/email.php. 因此,即使我不创建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. 它给出了一个空白页,没有错误消息(调试已经是2,如果有任何错误,它应该显示所有类型的错误消息),但是我没有收到任何电子邮件。 I also tried different email service provider like Yahoo and my school email. 我还尝试了其他电子邮件服务提供商,例如Yahoo和我的学校电子邮件。 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? 那么,有人对我错过了什么有任何想法吗?

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. 如您的问题所述,如果您使用各自的方法分别设置所有配置加载 配置 数组 ,则无需创建app / Config / email.php。

You are using Email::config() method to load a $default config array which is supposed to be defined somewhere. 您正在使用Email :: config()方法加载应该在某处定义的$default配置数组。 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). 作为一个好习惯,可以在app / Config / email.php中定义它,也可以在控制器的操作中定义它(不建议后者)。 CakeEmail needs to know the transport type, host, port, etc. CakeEmail需要知道传输类型,主机,端口等。

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. 阅读您在问题中提到的那一行之后的部分 ,该部分告诉您如何使用CakeEmail的构造CakeEmail或如何使用$config数组。

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

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